【发布时间】:2019-08-15 20:48:30
【问题描述】:
我正在尝试从 power shell 创建一个 Rest API,当我尝试运行脚本时出现以下错误。我不确定自己在犯什么错误。
我会把脚本和错误也放上去。请帮忙。
Script:
username = "admin"
password = "******"
authInfo = ("{0}:{1}" -f $username,$password)
authInfo = [System.text.Encoding]:: UTF8.GetByteCount($authInfo)
authInfo = [System.Convert]::ToBase64String($authInfo)
headers = @{Accept=("application/json");Contenttype=("appliaction/json");Authorization=("Basic {0}"-f $authInfo)}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::"tls12, tls11, tls"
Invoke-WebRequest -Uri https://njidlsdsapp01/support
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
uri = "https://njidlsdsapp01/support"
body = "{'login':'admin','login_pwd':'*****','commands' :['create a new support file']}"
标题
res = invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body $body
res
错误: PS C:\Users\njujjavarapu> C:\Users\njujjavarapu\Desktop\Snapshot.ps1 异常设置“SecurityProtocol”:“由于枚举值无效,无法将 null 转换为类型“System.Net.SecurityProtocolType”。指定以下枚举值之一,然后重试。可能的枚举值为 “系统默认,Ssl3,Tls,Tls11,Tls12”。 在 C:\Users\njujjavarapu\Desktop\Snapshot.ps1:7 char:1 + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolTy ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting
Invoke-WebRequest:请求被中止:无法创建 SSL/TLS 安全通道。 在 C:\Users\njujjavarapu\Desktop\Snapshot.ps1:8 char:1 + 调用 WebRequest -Uri https://njidlsdsapp01/support + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Name Value
---- -----
Contenttype appliaction/json
Accept application/json
Authorization Basic Eg==
invoke-RestMethod:请求被中止:无法创建 SSL/TLS 安全通道。 在 C:\Users\njujjavarapu\Desktop\Snapshot.ps1:19 char:8 + $res = invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Bo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
【问题讨论】:
标签: powershell