Invoke-WebRequest -InFile 'C:\test.apk' -Method Post -ContentType 'multipart/form-data' ('https://api.telegram.org/botXXX/sendDocument?chat_id=xxx&document') 

With this request, the error is:

Invoke-WebRequest: The secure channel was aborted: Could not create SSL / TLS secure channel

  • one
    Try to write more detailed questions. Explain exactly what you see the problem, how to reproduce it, what you want to get as a result, etc. - Nicolas Chabanovsky
  • "How to use the Powershell Invoke-WebRequest cmdlet to load a file of telegram bot api bot?" What's so incomprehensible? - Alex
  • It is not clear what you tried to do, and what exactly did you have a problem with? - Nicolas Chabanovsky
  • I tried to send my bot in the telegraph a file, using the Powershell cmdlet Invoke-WebRequest, when sending, I get the error: "The request was aborted: Could not create SSL / TLS secure channel" - Alex

1 answer 1

Could not create SSL / TLS secure channel

I will assume that the problem is that PowerShell cannot verify the validity of the certificate. Try adding the following code before calling Invoke-Webrequest :

 # Make invoke-webrequest to ignore cert check add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy 

It helped me, however, in the reverse situation - it was necessary to download from https to bypass certificate verification. I do not know how much it works in the opposite direction.

  • The same mistake ... - Alex