dub_beat

Hi,

for the past while ive been stuck with the following error when i debug my application

"The server committed a protocol violation. Section=ResponseStatusLine"

My application is sends 2 requests to a java servlet.

The first request works fine.

If I try to send any other request the error occurs.

Ive looked around online about the error.

I tried setting <httpWebRequest useUnsafeHeaderParsing="true" /> in the web config file but it does not work.

Also I read that the iis server has problems if another application is using port 80.

The servlet is configured to run on port 80 so I changed it to port 81.

I still get the error.

Im really baffled as to why this error is occuring.

Any help or insight would be greatly appreciated.

Thanks

Dub

/////Request 1

string url = "http://localhost:81/";
string result = string.Empty;
string postData = "msisdn0=862324984";
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri + "demo1_res");

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
// request.Referer = "http://localhost/demo1_res";
request.ProtocolVersion = HttpVersion.Version11;
Stream writeStream = request.GetRequestStream();
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(postData);
writeStream.Write(bytes, 0, bytes.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();



Stream responseStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(responseStream);
result = readStream.ReadToEnd();
////////////////////////////////////
/////Request 1

string url2 = "http://localhost:81/";
string result2 = string.Empty;
string postData2 = "info id=862324984&type=slir";
Uri uri2 = new Uri(url2);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:81/info id=862324984&type=slir");
request.Method = "Get";
request.ContentType = "application/x-www-form-urlencoded";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(responseStream);
string result = readStream.ReadToEnd();




Re: .NET Framework Networking and Communication http Response error

Mariya Atanasova - MSFT

You need to close the response before issueing a new HttpWebRequest. I would advise closing the stream as well.

responseStream.Close()

response.Close()

Do this in both your requests.

Mariya





Re: .NET Framework Networking and Communication http Response error

dub_beat

Hi, thanks for the reply.

I tried that but the error remains the same.

I also tried creating my response like this

using (HttpWebResponse responseFromCrk = (HttpWebResponse)requestToCrk.GetResponse())

.... which i believe automatically disposes of the object but it also did not work.

Have you any other ideas

Thanks

-dub




Re: .NET Framework Networking and Communication http Response error

Mariya Atanasova - MSFT

I see on the first request you have this line:

request.ProtocolVersion = HttpVersion.Version11;

and on the second request you don't have it. Could that be your issue

Thanks

Mariya