HTTP protocol violation - Urgent

  • Thread starter Thread starter sumit
  • Start date Start date
S

sumit

Hi,
I am trying to send an XML request from ASPX page to A
servlet,,,and gets the XML response back. I am using
HttpWebRequest object. It throws exception as:

The underlying connection was closed: The server committed
an HTTP protocol violation.

Previously it was working fine but suddenly it has given
error like this,,,,and sometimes this error comes but
sometimes it doesnot.

Please suggest

Thanks
Sumit
 
sumit said:
Hi,
I am trying to send an XML request from ASPX page to A
servlet,,,and gets the XML response back. I am using
HttpWebRequest object. It throws exception as:

The underlying connection was closed: The server committed
an HTTP protocol violation.

Previously it was working fine but suddenly it has given
error like this,,,,and sometimes this error comes but
sometimes it doesnot.

Please suggest

Um.. post some code?
 
code is as follows----

HttpWebRequest oHttpWebRequest = (HttpWebRequest)
(WebRequest.Create("http://xxx.com/abc/abc"));

Byte[] bytes = sXMLRequestStream.ToArray();

//convert byte array to string
string strReq;
strReq = Encoding.ASCII.GetString(bytes);

//convert byte array to string ends here
oHttpWebRequest.ContentType = "application/x-www-form-
urlencoded";
oHttpWebRequest.Method = "POST";
oHttpWebRequest.ContentLength = bytes.Length;
Stream oWStream = oHttpWebRequest.GetRequestStream();
oWStream.Write(bytes, 0, bytes.Length);
oWStream.Close();
//to receive
HttpWebResponse oHttpWebResponse = (HttpWebResponse)
(oHttpWebRequest.GetResponse());

OutResStream = oHttpWebResponse.GetResponseStream();


Pls suggest!!!1
 
sumit said:
code is as follows----

HttpWebRequest oHttpWebRequest = (HttpWebRequest)
(WebRequest.Create("http://xxx.com/abc/abc"));

Byte[] bytes = sXMLRequestStream.ToArray();

//convert byte array to string
string strReq;
strReq = Encoding.ASCII.GetString(bytes);

//convert byte array to string ends here
oHttpWebRequest.ContentType = "application/x-www-form-
urlencoded";
oHttpWebRequest.Method = "POST";
oHttpWebRequest.ContentLength = bytes.Length;
Stream oWStream = oHttpWebRequest.GetRequestStream();
oWStream.Write(bytes, 0, bytes.Length);
oWStream.Close();
//to receive
HttpWebResponse oHttpWebResponse = (HttpWebResponse)
(oHttpWebRequest.GetResponse());

OutResStream = oHttpWebResponse.GetResponseStream();

Two things seem wrong:

- You're using ASCII encoding. Is all your XML content really plain
ASCII? Otherwise you'll lose content here.

- The content type should not be "application/x-www-form-urlencoded",
because you're not posting a HTML form. Something like "text/xml" is
more appropriate here.

Cheers,
 
Back
Top