0

下面的代码需要 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
4

1 回答 1

0

如果您正在控制响应(url 指向您管理的服务器),您可以打开 GZIP 压缩。

http://blog.arvixe.com/how-to-enable-gzip-on-iis7/

于 2012-06-09T05:13:58.673 回答