HTTP protocol violation - Urgent

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
 
J

Joerg Jooss

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?
 
S

sumit

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
 
J

Joerg Jooss

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,
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top