下面的代码需要 150 到 200 秒来读取数据(实际上我的响应数据非常大)请提供任何替代方案来解决此问题。
Protected Function PostXml(ByVal url As String, ByVal xml As String) As String
Dim strResult As String = String.Empty
Dim bytes As Byte() = Encoding.UTF8.GetBytes(xml)
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
request.Method = "POST"
request.ContentLength = bytes.Length
request.ContentType = "text/xml"
Using requestStream As Stream = request.GetRequestStream()
requestStream.Write(bytes, 0, bytes.Length)
End Using
Using response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
If response.StatusCode <> HttpStatusCode.OK Then
Dim message As String = [String].Format("POST failed. Received HTTP {0}", response.StatusCode)
Throw New ApplicationException(message)
Else
Dim reader As StreamReader = Nothing
Dim responseStream As Stream = response.GetResponseStream()
reader = New StreamReader(responseStream, Encoding.Default)
**strResult = reader.ReadToEnd() 'Here is taking to much time**
response.Close()
responseStream.Close()
reader.Close()
End If
End Using