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?
16 8041
Ive checked other resources and i still haven't had any luck :(
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
ive already tried that, still same outcome :(
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"
*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
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
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.
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?
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;
-
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!
no prevail! It still happens..gah this is soo fustrating :(
...and why does youtube.com throw a 400 error?
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...
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.. :(
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?
I guess you could try putting it RIGHT before any of your httpwebrequest stuff?
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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();...
|
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...
|
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()...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| |