我们有两个执行 POST 和 GET 请求的 API。它们过去都可以正常工作,但是执行 POST 的 API 开始出现错误:
Invoke-WebRequest:底层连接是:接收时发生意外错误。`
几天来,我一直在尝试研究,所有 KB 都指向某种 SSL/TLS 并添加了这段代码:
[Net.ServicePointManager]::SecurityProtocol = "SystemDefault,Tls12, Tls11, Tls, Ssl3"
但我从一开始就已经有了这个代码。但是,我找不到解决问题的方法。
操作系统:Windows 2012
PowerShell 版本:4.0
function funName ($Val1, $Val2) {
[Net.ServicePointManager]::SecurityProtocol = "SystemDefault,Tls12, Tls11, Tls, Ssl3"
#[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
$url = "https://someAPI/post.request/do-something"
$user = "username"
$pass = "password"
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds "
$Headers = @{
"Accept"="application/json"
Authorization = $basicAuthValue
}
$Body = @{
'@type' ='x'
parm1 = $Val1
parm2 = $Val2
}
#[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $url -Headers $Headers -Method Post -Body $Body | Out-Null
}
## Deactivation Request ffffffff##
funName -RequestID Val1 adID Val2
如前所述,这种情况一直持续到上周。