Computing.Net > Forums > Programming > http post in C#

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

http post in C#

Reply to Message Icon

Name: coolkang
Date: February 25, 2005 at 10:03:16 Pacific
OS: xp
CPU/Ram: 512
Comment:

hello helper
I have a problem in passing a string to the http post site. the code example i have converted string to byte and send it to the http site. The problem with that is the http post site does not understand the encoding. So I want to know is there a way i can pass a string without converting it to byte? Thank you very much

Here is the code i have:

byte [] bytes = System.Text.Encoding.Unicode.GetBytes(postData);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);



Sponsored Link
Ads by Google

Response Number 1
Name: Chi Happens
Date: March 1, 2005 at 06:14:51 Pacific
Reply:

Here's how to do a post using c#

private string HttpPost(string URI, string Parameters) 
{
   System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
   req.Proxy = new System.Net.WebProxy(ProxyString, true);

   req.ContentType = "application/x-www-form-urlencoded";
   req.Method = "POST";

   byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
   req.ContentLength = bytes.Length;

   System.IO.Stream os = req.GetRequestStream ();
   os.Write (bytes, 0, bytes.Length); 
   os.Close ();

   System.Net.WebResponse resp = req.GetResponse();
   if (resp== null) return null;

   System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
   return sr.ReadToEnd().Trim();
}


Hope this helps,
Chi

They mostly come at night...mostly


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: http post in C#

URL-highlighting TextBoxes in C#? www.computing.net/answers/programming/urlhighlighting-textboxes-in-c/12814.html

Simple design questions in C++ www.computing.net/answers/programming/simple-design-questions-in-c/4384.html

Environment Variables in C# www.computing.net/answers/programming/environment-variables-in-c/13393.html