+2 votes
by
Do this:

$file = Get-Content -Path "C:\1.txt"
$uri = "https://api.telegram.org/botXXXX/sendDocument?chat_id=XXXXX&document"
Invoke-RestMethod -Method Post -Uri $uri -ContentType 'multipart/form-data' -Body [byte]$file


При выполнении ошибка:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

прошу помощи, заранее благодарен

2 Answers

0 votes
by
 
Best answer
from Windows Powershell, there is no direct support for 'multipart/form-data', only the Core

In particular, for multipartне enough guidance bondaryв ContentType
You can try to experiment with the manual Assembly such as here @jklemmack
https://stackoverflow.com/questions/36268925/power...
or with System.Net.Http.MultipartFormDataContent
0 votes
by
in the 7th (and, it seems, in the 6th) powersale works like this:

$token = "ХХХХХХХХХХХ"
$chat_id = "ХХХХХХХХХ"
$uri = "https://api.telegram.org/bot$Token/sendDocument"
$fileObject= get-item C:\test\1.pdf
$Form = @{
chat_id = $Chat_ID
document = $fileObject

}#form
$invokeRestMethodSplat = @{
Uri = $Uri
ErrorAction = 'Stop'
Form = $Form
Method = 'Post'
}

Invoke-RestMethod @invokeRestMethodSplat


в 5ом нет параметра форм в Invoke-RestMethod и там нужны пляски с бубном.
...