| GingerNinja 2004-11-16, 6:54 pm |
| Hi Guys,
I'm using the following code in C# to make an Http Request to a web
site, unfotunitely when I get the request back from the website it
only returns the first 4 characters of the response (which I know
should be much longer than that). I've tried the URL in a web browser
and the response is fine, I've also tried this in Java and again no
problems ( ly this has to be in C#, Java will not do).
String parameters = "one=1&two=2";
String post_url = "http://[ipaddress]";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(post_url);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
//Now we need to read the data length for post
req.ContentLength = parameters.Length;
//POST it
Stream strWrite = req.GetRequestStream();
StreamWriter sw = new StreamWriter(strWrite);
sw.Write(parameters.ToString());
sw.Flush();
sw.Close();
//Read the response back in
WebResponse wr = req.GetResponse();
HttpWebResponse httpRes = (HttpWebResponse)wr;
Stream s = httpRes.GetResponseStream();
StreamReader sr = new StreamReader(s,Encoding.UTF8);
String ret = sr.ReadToEnd();
httpRes.Close();
Console.WriteLine(ret);
Any thoughts, help much appreciated.
|