Click here to Skip to main content
14,699,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Simple Xml Http Request and response taking 150 to 200 Second for resolve this I try to gzip http Request and response, with below code then getting Error. The remote server returned an error: (500) Internal Server Error.

Please Help me, how to solve this problem

Protected Function PostXml(ByVal url As String, ByVal xml As String) As String
        Dim strResult As String = String.Empty
        Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)

        request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate")
        
If Not String.IsNullOrEmpty(xml) Then
            request.Method = "POST"
            Dim lbPostBuffer As Byte() = Encoding.[Default].GetBytes(xml)
            request.ContentLength = lbPostBuffer.Length
            Dim PostStream As Stream = request.GetRequestStream()
            PostStream.Write(lbPostBuffer, 0, lbPostBuffer.Length)
            PostStream.Close()
        End If
       
 Try
            Using WebResponse As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
                'Dim WebResponse As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
                Dim responseStream As Stream = WebResponse.GetResponseStream()
               
 If WebResponse.ContentEncoding.ToLower().Contains("gzip") Then
                    responseStream = New GZipStream(responseStream, CompressionMode.Decompress)
                ElseIf WebResponse.ContentEncoding.ToLower().Contains("deflate") Then
                    responseStream = New DeflateStream(responseStream, CompressionMode.Decompress)
                End If
               
 Dim Reader As New StreamReader(responseStream, Encoding.[Default])
                Dim Html As String = Reader.ReadToEnd()
                WebResponse.Close()
                responseStream.Close()
                strResult = Html
            End Using
        Catch ex As WebException
            strResult = ""
        End Try
        Return strResult
    End Function
Posted
Updated 18-May-12 3:05am
v3
Comments
Bernhard Hiller 18-May-12 2:38am
   
"getting Error":
Tell us more about that error! Otherwise we won't be able to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900