For Programmers: Free Programming Magazines  


Home > Archive > C# > November 2004 > HttpConnection









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author HttpConnection
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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com