HttpWebRequest method fails against Ravenous web server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alaskaman
    New Member
    • Jan 2013
    • 1

    HttpWebRequest method fails against Ravenous web server

    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.WebE xception: The server committed a protocol violation. Section=Respons eStatusLine

    The code I am using is as follows:

    Code:
    Function WRequest(URL As String, method As String, POSTdata As String) As String
      Dim responseData As String = ""
      Try
        Dim hwrequest As Net.HttpWebRequest = Net.Webrequest.Create(URL)
        hwrequest.Accept = "*/*"
        hwrequest.AllowAutoRedirect = True
        hwrequest.UserAgent = "http_requester/0.1"
        hwrequest.Timeout = 60000
        hwrequest.Method = method
    
        If hwrequest.Method = "POST" Then
          hwrequest.ContentType = "application/x-www-form-urlencoded"
          Dim encoding As New System.Text.ASCIIEncoding() 'Use UTF8Encoding for XML requests
          Dim postByteArray() As Byte = encoding.GetBytes(POSTdata)
          hwrequest.ContentLength = postByteArray.Length
          Dim postStream As IO.Stream = hwrequest.GetRequestStream()
          postStream.Write(postByteArray, 0, postByteArray.Length)
          postStream.Close()
        End If
    
        Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
    
        If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
          Dim responseStream As IO.StreamReader = New IO.StreamReader(hwresponse.GetResponseStream())
          responseData = responseStream.ReadToEnd()
        End If
    
        hwresponse.Close()
      Catch e As Exception
        responseData = "An error occurred: " & e.Message
      End Try
    
      Return responseData
    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:

    <httpWebReque st useUnsafeHeader Parsing = "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?
    Last edited by Frinavale; Jan 25 '13, 07:19 PM. Reason: Added indentation to code for redability
Working...