WebRequest.GetResponse()抛出NullReferenceException

时间:2017-05-16 17:10:17

标签: vb.net

在发出Web请求时,在将数据写入服务器后,调用GetResponse()会抛出NullReferenceException。当我单步执行代码时(即:通过F10),但是当我继续在调试中(即:通过F5)时,这不会发生。

Using dataStream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        Dim responseDoc As String = String.Empty

        Using response = CType(request.GetResponse(), HttpWebResponse) ' NullReferenceException Here
            Dim responseStream As IO.Stream = response.GetResponseStream()
            Dim readStream As New System.IO.StreamReader(responseStream, encoding)
            responseDoc = readStream.ReadToEnd()
        End Using
End Using

0 个答案:

没有答案