HttpWebResponse不要从流BinaryReader中抽取字节

时间:2018-03-14 08:52:24

标签: powershell system.net.httpwebrequest getresponsestream

我在System.net.HttpWebResponse中使用此方法。但我无法将所有字节都放入变量中,我该怎么办?

    [System.Net.HttpWebRequest] $webRequest = [System.Net.WebRequest]::Create('URl')
    $webRequest.Timeout = 300000
    $webRequest.Method = 'POST'
    $webRequest.ContentType = 'multipart/form-data'
    $webRequest.ContentLength = $data.Length;
    $requestStream = $webRequest.GetRequestStream()
    $requestStream.Write($data, 0, $data.Length)
    $requestStream.Flush()
    $requestStream.Close()
    [System.Net.HttpWebResponse] $webResponse = $webRequest.GetResponse()
$streamReader = New-Object IO.BinaryReader($webResponse.GetResponseStream())
$ByteArr = $streamReader.ReadBytes($streamReader.BaseStream.Length)

为什么$streamReader.BaseStream.length没有长度?当我使用流泵浦字节中的$streamReader.ReadByte()方法时。有矛盾吗?

0 个答案:

没有答案