By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

HttpWebRequest method fails against Ravenous web server

P: 1
I am attempting to retrieve the response stream from a Ravenous web server (http://ostatic.com/ravenous) without success. I consistenly get the following error:

System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine

The code I am using is as follows:

Expand|Select|Wrap|Line Numbers
  1. Function WRequest(URL As String, method As String, POSTdata As String) As String
  2.   Dim responseData As String = ""
  3.   Try
  4.     Dim hwrequest As Net.HttpWebRequest = Net.Webrequest.Create(URL)
  5.     hwrequest.Accept = "*/*"
  6.     hwrequest.AllowAutoRedirect = True
  7.     hwrequest.UserAgent = "http_requester/0.1"
  8.     hwrequest.Timeout = 60000
  9.     hwrequest.Method = method
  10.  
  11.     If hwrequest.Method = "POST" Then
  12.       hwrequest.ContentType = "application/x-www-form-urlencoded"
  13.       Dim encoding As New System.Text.ASCIIEncoding() 'Use UTF8Encoding for XML requests
  14.       Dim postByteArray() As Byte = encoding.GetBytes(POSTdata)
  15.       hwrequest.ContentLength = postByteArray.Length
  16.       Dim postStream As IO.Stream = hwrequest.GetRequestStream()
  17.       postStream.Write(postByteArray, 0, postByteArray.Length)
  18.       postStream.Close()
  19.     End If
  20.  
  21.     Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
  22.  
  23.     If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
  24.       Dim responseStream As IO.StreamReader = New IO.StreamReader(hwresponse.GetResponseStream())
  25.       responseData = responseStream.ReadToEnd()
  26.     End If
  27.  
  28.     hwresponse.Close()
  29.   Catch e As Exception
  30.     responseData = "An error occurred: " & e.Message
  31.   End Try
  32.  
  33.   Return responseData
  34. End Function
This code works fine for requests against Yahoo.com, Google.com and other websites I have tried but any request against a Ravenous web server fails with the above error.

I have tried modifying the app.config like so:

<httpWebRequest useUnsafeHeaderParsing = "true"/>

with no joy.

I have searched and searched the web for answers, trying all different types of code and app.config modifications without success. Does anyone have any experience with a Ravenous web server?
Jan 23 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.