I need help with something it drives me nuts. I have an application which send XML to a web server through a POST method. This part works excellent. But where I have issues is with receiving the standard response from the web server for OK or error. Instead of receiving the actual response, I get the error message" WebException was unhandled. The server committed a protocol violation. Section=ResponseStatusLine" . The response I should receive is in XML format where I have as elements the error result (ok or error), the error number and the error description. Here is the code I have:
Public Sub REQRESP() Dim response As HttpWebResponse = Nothing Dim reader As StreamReader ' Create a request using a URL that can receive a post. Dim request As HttpWebRequest = HttpWebRequest.Create("http://"192.168.0.1/test/test.xml") ' Set the Method property of the request to POST. request.Method = "POST" ' Create POST data and convert it to a byte array. Dim postData As String = _ "<TEST INFO='TEST'><CITY CODE='PO'>test</CITY></TEST>" Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData) ' Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded" ' Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length ' Get the request stream. Dim dataStream As Stream = request.GetRequestStream() ' Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length) ' Close the Stream object. dataStream.Close() Try ' Get response response = DirectCast(request.GetResponse(), HttpWebResponse) ' Get the response stream into a reader reader = New StreamReader(response.GetResponseStream()) ' Console application output Label1.Text = reader.ReadToEnd() Finally If Not response Is Nothing Then response.Close() End Try End Sub
The code stops at "response = DirectCast(request.GetResponse(), HttpWebResponse)" and gives me the above mentioned error. I searched the web for an answer to this but no success so far. Hopefully here is the right place to ask for help with this issue I have.