1

PowerShell 4.0
Windows Server 2012 R2

Hello, I have a handshake method to GET token, like

$response = Invoke-WebRequest -Uri "https://**.**.**.**:port/token/" -Method GET -Headers @{Authorization = "Basic blahblahblah"} -Body @{grant_type="client_credentials"} 

Then I have an error

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

Postman and CURL is working, does anybody knows how to disable certificate checking in POSH script ?

Following things don't help me:

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;
    }
}
"@
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
Wasif
  • 14,755
  • 3
  • 14
  • 34
ernekyan
  • 31
  • 1
  • 9
  • 1
    And you are sure the channel is open for the ssl port? – Sid Dec 26 '19 at 07:34
  • 1
    Does this answer your question? [Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel](https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel) – Guenther Schmitz Dec 26 '19 at 07:48
  • @Guenther Schmitz , nope, plz read my description full, i wrote that this doesn't help – ernekyan Dec 26 '19 at 08:29
  • 1
    the syntax differs that's why i asked. please try `[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12` and test the invoke again. – Guenther Schmitz Dec 26 '19 at 08:33
  • 1
    i remove "s" in "https" and change port, thx all – ernekyan Dec 26 '19 at 08:52

0 Answers0