Protocol Violation  | Member | | Join Date: Jul 2008
Posts: 77
| |
Here is my code snippet: -
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
-
request.KeepAlive = true;
-
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
-
//The GetResponse is where the error occurs
-
Stream responsestream = response.GetResponseStream();
-
Error:The server committed a protocol violation. Section=ResponseStatusLine
I can get the response from certain sites but then some cause my program to throw that error.
Is there anything i can do?
|  | Member | | Join Date: Jul 2008
Posts: 77
| | | re: Protocol Violation
Ive checked other resources and i still haven't had any luck :(
|  | Site Addict | | Join Date: Jul 2008 Location: US of A
Posts: 587
| | | re: Protocol Violation
could it be the .keepalive method ? try it without, because you said some site's right? or like in a try catch statement, set the .keepalive to false and redo the method maybe...
joedeene
|  | Member | | Join Date: Jul 2008
Posts: 77
| | | re: Protocol Violation
ive already tried that, still same outcome :(
|  | Site Addict | | Join Date: Jul 2008 Location: US of A
Posts: 587
| | | re: Protocol Violation Quote:
Originally Posted by Kevinyy ive already tried that, still same outcome :( *THE FOLLOWING IS A POST FROM A DIFFERENT USER ON A DIFFERENT FORUM TO SEE THE LINK PLEASE PM ME: Quote:
Originally Posted by Steven Cheng(OTHER SITE) From your description, you're using the HttpWebRequest component to send
some http request to some external web resource in your ASP.NET web
application. However, you're always getting the "The server committed a
protocol violation. Section=ResponseStatusLine" error unless you set the
following section in the web.config file:
==========
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
==========
and you're wondering the cause of this behavior ,correct?
As for this issue, I've performed some research on this and found that the
problem is actually caused by the critical http header parsing/validating
of the HttpWebRequest component. According to the Http
Specification(http1.1), the HTTP header keys shoud specifically not include
any spaces in their names. However, some web servers do not fully respect
standards they're meant to. Applications running on the Dotnet framework
and making heavy use of http requests usually use the httpWebRequest class,
which encapsulates everything a web oriented developer could dream of. With
all the recently issues related to security, the "httpWebRequest" class
provides a self protection mechanism preventing it to accept HTTP answers
which not fully qualify to the specifications.
The common case is having a space in the "content-length" header key. The
server actually returns a "content length" key, which, assuming no spaces
are allowed, is considered as an attack vector (HTTP response split
attack), thus, triggering a "HTTP protocol violation error" exception.
And it is possible since the 1.1 SP 1 DotNet version to disable this error
check. Fortunately, DotNet allows you to modify some parameters directly
through a simple text configuration file . and that's just the setting
you mentioned ealier in your message.
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
Hope this helps clarify this problem some.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead so it sounds similar to your problem, if your using asp.net, if not try typing the error code in google...
joedeene
**i take no credit for the work of "Steven Cheng"
|  | Member | | Join Date: Jul 2008
Posts: 77
| | | re: Protocol Violation Quote:
Originally Posted by joedeene *THE FOLLOWING IS A POST FROM A DIFFERENT USER ON A DIFFERENT FORUM TO SEE THE LINK PLEASE PM ME:
so it sounds similar to your problem, if your using asp.net, if not try typing the error code in google...
joedeene
**i take no credit for the work of "Steven Cheng" how do i add this modification? (useUnsafeHeaderParsing="true|false")
C#.Net2.2
|  | Site Addict | | Join Date: Jul 2008 Location: US of A
Posts: 587
| | | re: Protocol Violation Quote:
Originally Posted by Kevinyy how do i add this modification? (useUnsafeHeaderParsing="true|false")
C#.Net2.2 well if your using asp.net that goes into a config file right? or are you just doing a windows app?
joedeene
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,158
| | | re: Protocol Violation
According to HTTP protocol, all responses to a web request should start something like this:
"HTTP/1.1 200 OK"+(newline)
The error occurs when, for some servers, when serving up a certain type of file (varriable, depending on how the server software was built, or software age), that line is left out. I had the same errors in a program I wrote, because I forgot to include that line for some special AJAX pages.
As to how to fix it, looks like you found that. The statement looks like it would go somewhere in either the web.config file.
|  | Member | | Join Date: Jul 2008
Posts: 77
| | | re: Protocol Violation Quote:
Originally Posted by Plater According to HTTP protocol, all responses to a web request should start something like this:
"HTTP/1.1 200 OK"+(newline)
The error occurs when, for some servers, when serving up a certain type of file (varriable, depending on how the server software was built, or software age), that line is left out. I had the same errors in a program I wrote, because I forgot to include that line for some special AJAX pages.
As to how to fix it, looks like you found that. The statement looks like it would go somewhere in either the web.config file. Im writing a windows app. and i dont have a web.config file to amend, what should i do?
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,158
| | | re: Protocol Violation Quote:
Originally Posted by Kevinyy Im writing a windows app. and i dont have a web.config file to amend, what should i do? Well I honesty am not sure where you would put this code, somewhere that happens at the begining of the program I would think -
System.Net.Configuration.HttpWebRequestElement hwre = new System.Net.Configuration.HttpWebRequestElement();
-
hwre.UseUnsafeHeaderParsing = true;
-
|  | Member | | Join Date: Jul 2008
Posts: 77
| | | re: Protocol Violation Quote:
Originally Posted by Plater Well I honesty am not sure where you would put this code, somewhere that happens at the begining of the program I would think -
System.Net.Configuration.HttpWebRequestElement hwre = new System.Net.Configuration.HttpWebRequestElement();
-
hwre.UseUnsafeHeaderParsing = true;
-
ahhhh ok ill try that out, thank you!
|  | Member | | Join Date: Jul 2008
Posts: 77
| | | re: Protocol Violation
no prevail! It still happens..gah this is soo fustrating :(
...and why does youtube.com throw a 400 error?
|  | Forum Leader | | Join Date: Apr 2008 Location: San Antonio, TX (USA)
Posts: 2,608
| | | re: Protocol Violation Quote:
Originally Posted by Kevinyy no prevail! It still happens..gah this is soo fustrating :(
...and why does youtube.com throw a 400 error? A 400 Error is a bad request...
|  | Member | | Join Date: Jul 2008
Posts: 77
| | | re: Protocol Violation Quote:
Originally Posted by insertAlias A 400 Error is a bad request... i know...but youtube.com is a fine request - so i dont see whats going on there.
and not including the youtube thing, the program still errors with the Protocol Violation.. :(
|  | Member | | Join Date: Jul 2008
Posts: 77
| | | re: Protocol Violation Quote:
Originally Posted by Plater Well I honesty am not sure where you would put this code, somewhere that happens at the begining of the program I would think -
System.Net.Configuration.HttpWebRequestElement hwre = new System.Net.Configuration.HttpWebRequestElement();
-
hwre.UseUnsafeHeaderParsing = true;
-
Is there a certain way to use this? i added the reference to System.Net.Configuration, and i placed that code in the beginning of the program, would i have to change my program more to make use of that configuration?
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,158
| | | re: Protocol Violation
I guess you could try putting it RIGHT before any of your httpwebrequest stuff?
|  | Site Addict | | Join Date: Jul 2008 Location: US of A
Posts: 587
| | | re: Protocol Violation Quote:
Originally Posted by Kevinyy Is there a certain way to use this? i added the reference to System.Net.Configuration, and i placed that code in the beginning of the program, would i have to change my program more to make use of that configuration? Perhaps take a look at this LINK
joedeene
|  | Similar .NET Framework bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,366 network members.
|