473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Protocol Violation

Kevinyy
77
Here is my code snippet:
Expand|Select|Wrap|Line Numbers
  1. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
  2. request.KeepAlive = true;
  3. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  4.  //The GetResponse is where the error occurs
  5. Stream responsestream = response.GetResponseStream();
  6.  
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?
Sep 5 '08 #1
16 8041
Kevinyy
77
Ive checked other resources and i still haven't had any luck :(
Sep 5 '08 #2
joedeene
583 512MB
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
Sep 5 '08 #3
Kevinyy
77
ive already tried that, still same outcome :(
Sep 5 '08 #4
joedeene
583 512MB
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:

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"
Sep 5 '08 #5
Kevinyy
77
*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
Sep 5 '08 #6
joedeene
583 512MB
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
Sep 5 '08 #7
Plater
7,872 Expert 4TB
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.
Sep 5 '08 #8
Kevinyy
77
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?
Sep 5 '08 #9
Plater
7,872 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. System.Net.Configuration.HttpWebRequestElement hwre = new System.Net.Configuration.HttpWebRequestElement();
  2. hwre.UseUnsafeHeaderParsing = true;
  3.  
Sep 5 '08 #10
Kevinyy
77
Well I honesty am not sure where you would put this code, somewhere that happens at the begining of the program I would think
Expand|Select|Wrap|Line Numbers
  1. System.Net.Configuration.HttpWebRequestElement hwre = new System.Net.Configuration.HttpWebRequestElement();
  2. hwre.UseUnsafeHeaderParsing = true;
  3.  
ahhhh ok ill try that out, thank you!
Sep 5 '08 #11
Kevinyy
77
no prevail! It still happens..gah this is soo fustrating :(
...and why does youtube.com throw a 400 error?
Sep 5 '08 #12
Curtis Rutland
3,256 Expert 2GB
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...
Sep 5 '08 #13
Kevinyy
77
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.. :(
Sep 6 '08 #14
Kevinyy
77
Well I honesty am not sure where you would put this code, somewhere that happens at the begining of the program I would think
Expand|Select|Wrap|Line Numbers
  1. System.Net.Configuration.HttpWebRequestElement hwre = new System.Net.Configuration.HttpWebRequestElement();
  2. hwre.UseUnsafeHeaderParsing = true;
  3.  
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?
Sep 6 '08 #15
Plater
7,872 Expert 4TB
I guess you could try putting it RIGHT before any of your httpwebrequest stuff?
Sep 8 '08 #16
joedeene
583 512MB
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
Sep 8 '08 #17

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

Similar topics

5
by: Henrik | last post by:
Hi, I am trying to read some industrial webservers using the HTTP/CGI webequest like this: wrs = (HttpWebRequest)WebRequest.Create(HTTP/CGI-string); mwst = (HttpWebResponse wrs.GetResponse();...
1
by: ATS | last post by:
ERR - WebClient.DownloadData returns "protocol violation" Please help, I'm getting a "protocol violation" from a site that is working perfectly fine when I issue WebClient.DownloadData as...
0
by: Helen | last post by:
Hi, I am trying to use a .Net WebClient object to read data from a url, but I am getting the following error: System.Net.HttpWebRequest.CheckFinalStatus()...
1
by: Dan W. | last post by:
Does anyone have any experience with this problem. I am trying to post about 20 fields of information to another server using System.Net.WebClient.UploadData. This works fine for some servers but...
7
by: Tom | last post by:
Hello all: I have a method that does a POST to a secured website using HttpWebRequest. It worked when logging in the site, but it failed with an HTTP prococol violation error when it is used to...
1
by: Khadim | last post by:
I m using HTTWebResponse which is running smoothly on my system which is behing a proxy server. When I run the application with Live IP it gives "HTTP Protocol violation error" I can't use...
0
by: Kris Mattheus | last post by:
A little background: I've been using web services successfully for a while now. My web server is a Windows CE 4.2 device and my client is a windows C# application created with Visual Studio 2003....
3
by: Scott McDermott | last post by:
I have an application that is making an HTTP request with HttpWebRequest.GetRequest. Unless I set 'httpWebRequest useUnsafeHeaderParsing="true"' in the web.config, I get a 'The server committed a...
0
by: Marcus Ogden | last post by:
Hello, A client of ours using the Squid proxy server (version 2.5.STABLE6-3.4E.12.1) on Red Hat Enterprise Linux 4 is experiencing a problem when running our .NET 2.0 client application, which...
0
by: oriol.ardevol | last post by:
Hi, I have an asp.net application that connects through an HttpWebRequest object to a ISAPI dll in a server. This isapi dll has some different method calls. What I do is calling the different...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.