ServerProtocolViolation after HttpWebRequest.GetResponse()

G

Guest

I have a strange behavior of a following code:

HttpWebRequest
request=(HttpWebRequest)WebRequest.Create(@"http://.../target.jsp");
request.ProtocolVersion=HttpVersion.Version11;
request.Method="POST";
request.ContentType="text/plain";
request.KeepAlive = true;
request.ContentLength=data.Length;
try
{
Stream newStream=request.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();
HttpWebResponse response=(HttpWebResponse)request.GetResponse();
//Exception here
...
}
catch
{

}

After GetResponse is called I receive exception with Status =
WebExceptionStatus.ServerProtocolViolation.

I used sniffer to scan which requests/reponses are being handled during this
operation from IE and from my code - all of requests/responses are the
same - response is HTTP 200 OK for both ways of request.

Does anybody can shed a light why .Net Framework returns such an exception
even if response status is OK?
 
J

Joerg Jooss

I have a strange behavior of a following code:

HttpWebRequest
request=(HttpWebRequest)WebRequest.Create(@"http://.../target.jsp");
request.ProtocolVersion=HttpVersion.Version11;
request.Method="POST";
request.ContentType="text/plain";
request.KeepAlive = true;
request.ContentLength=data.Length;
try
{
Stream newStream=request.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();
HttpWebResponse response=(HttpWebResponse)request.GetResponse();
//Exception here
...
}
catch
{

}

After GetResponse is called I receive exception with Status =
WebExceptionStatus.ServerProtocolViolation.

I used sniffer to scan which requests/reponses are being handled
during this operation from IE and from my code - all of
requests/responses are the same - response is HTTP 200 OK for both
ways of request.

Does anybody can shed a light why .Net Framework returns such an
exception even if response status is OK?

Your code sample isn't suspicious (the fact that you post text/plain
content is a conscious choice, isn't it?).

Can you post a HTTP trace?

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top