Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Developer,

I am trying to request to Java Server Socket but they are unable to receive my data_string (data="ABC").

They receive with error....
"java.io.StreamCorruptedException: invalid stream header: 56455249"

my code is as below...
C#
string url = "http://www.myserverurl.com";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                string proxy = null;

                string data = "ABC";
                byte[] buffer = Encoding.UTF8.GetBytes(data);

                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = buffer.Length;
                req.Proxy = new WebProxy(proxy, true);
                req.CookieContainer = new CookieContainer();

                Stream reqst = req.GetRequestStream(); // add form data to request stream 
                reqst.Write(buffer, 0, buffer.Length);
                reqst.Flush();
                reqst.Close();


I require Stream obj to send data to server as string and not as byte. How to do so?

Thanks in advance.

Regards,
Rajesh Katare
Posted
Updated 24-Jun-11 4:58am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900