Invoke-WebRequest SSL fails?

前端 未结 4 1741
走了就别回头了
走了就别回头了 2020-12-02 19:00

When I try to use Invoke-WebRequest I\'m getting some weird error:

Invoke-WebRequest -Uri \"https://idp.safenames.com/\"

Invoke-WebRequest : Th         


        
4条回答
  •  执念已碎
    2020-12-02 19:04

    As BaconBits notes, .NET version > 4.5 uses SSLv3 and TLS 1.0 by default.

    You can change this behavior by setting the SecurityProtocol policy with the ServicePointManager class:

    PS C:\> $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
    PS C:\> [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
    PS C:\> (Invoke-WebRequest -Uri "https://idp.safenames.com/").StatusCode
    200
    

    This will apply to all requests in the AppDomain (so it only applies to the current instance of the host application).


    There's a module on GitHub and in PSGallery that can manage these settings now:

    Install-Module BetterTls -Scope CurrentUser
    Import-Module BetterTls
    Enable-Tls -Tls11 -Tls12
    

提交回复
热议问题