powershell底层连接已关闭:发送

时间:2017-09-01 13:02:27

标签: powershell

我是Powershell的新手并创建了一些断点来弄清楚脚本超时的原因。但我收到了以下错误。任何帮助将不胜感激。

  

使用“0”参数调用“GetRequestStream”的异常:“The   底层连接已关闭:a上发生意外错误   发送。“在C:\ Users \ ksingh \ Documents \ SQL   scripts \ pdfimportPowerShell.ps1:155 char:5   + $ requestStream = [System.IO.Stream] $ request.GetRequestStream()   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~       + CategoryInfo:NotSpecified:(:) [],MethodInvocationException       + FullyQualifiedErrorId:WebException

以下是脚本的一部分,错误发生在---

bytes = [System.Text.Encoding]::ASCII.GetBytes($data)

调用令牌服务的函数

function GetNewToken()
{
    $request = [Net.WebRequest]::Create($temptokenserviceurl)

    $request.ServicePoint.Expect100Continue = $false

    $request.ContentType = "application/json"

    $request.Method = "POST"

    $data = (New-Object PSObject |
        Add-Member -PassThru NoteProperty username $temptokenserviceuser |    
        Add-Member -PassThru NoteProperty password $temptokenservicepassword
    ) | ConvertTo-JSON

    $bytes = [System.Text.Encoding]::ASCII.GetBytes($data)

    $request.ContentLength = $bytes.Length

    $requestStream = [System.IO.Stream]$request.GetRequestStream()

    $requestStream.write($bytes, 0, $bytes.Length)

    $response = $request.GetResponse()

    $StreamReader = New-Object IO.StreamReader($response.getResponseStream())

    $Json = $StreamReader.ReadToEnd()

    $responseString = $Json | ConvertFrom-Json

    $response.Close()

    return $responseString.tokenId
}

0 个答案:

没有答案