server committed an HTTP protocol violation

Posted on 2005-04-23
Last Modified: 2011-09-20
I finally got back to a project that I have not worked on in several months.  It was working as expected then, but now I am getting this error.  I suspect it has to do with the increased security from various system updates from Microsoft.  This portion of the program sends out the URL stored in "strHTML" merged with "searchtype" and "strURL" to create a string looking like


I get the error at the "objResponse = objRequest.GetResponse" line...

   "Run-time exception thrown : System.Net.WebException - The underlying connection was closed: The server committed an HTTP protocol violation"

The opening system arguements are...

   Imports System.Text.RegularExpressions
   Imports System.IO

And the subroutine is...

Private Function Scrape(ByVal searchtype As String, ByVal strURL As String) As String
   Dim objRequest As Net.WebRequest                                     ' Request to a Uniform Resource Identifier  
   Dim TimeoutInSeconds As Integer = 10                                     ' Default responce timeout (Move to INI)
   Dim objResponse As Net.WebResponse                                     ' Response from a Uniform Resource Identifier
   Dim objStreamReceive As System.IO.Stream                     ' Holder for received encoded data
   Dim objEncoding As System.Text.Encoding                                     ' Unicode encoding method
   Dim objStreamRead As System.IO.StreamReader                     ' Character input  
   Dim strHTML As String = ""           ' Move this string to INI eventually

      ' Setup web request and send obj
      objRequest = Net.WebRequest.Create(strHTML & searchtype & "?SEARCH=" & strURL)
      ' Convert request multiplier to milliseconds and start timer
      Request.Timeout = TimeoutInSeconds * 2000
      ' Response from internet request
      objResponse = objRequest.GetResponse
      ' Retrieve data stream from internet
      objStreamReceive = objResponse.GetResponseStream
      objEncoding = System.Text.Encoding.GetEncoding("utf-8")' Sets unicode encoding
      ' Reads characters from stream
      objStreamRead = New System.IO.StreamReader(objStreamReceive, objEncoding)
      ' Set function return value
      Scrape = objStreamRead.ReadToEnd()
      ' Check if available, then close response
      If Not objResponse Is Nothing Then
         ' Cleans up the resources and closes the stream
      End If
         ' Error occured requesting data, Make a pretty error message
         Return "Network Error"
      End Try
End Function ' Scrape

Any ideas?

Question by:kpalmate

    Author Comment

    Well after getting really annoyed, I dug deeper.

    I had seen this work around before, but geared to asp config files.  This shows the work around for ado executables like mine.  It worked.  

    Author Comment

    Until I recomplied the job and the config file disappeared.
    Anyway to incorporate the work around into the program itself?
    Any further ideas or comments.  These points are still live.

    Author Comment

    No problem

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now