2013年6月3日 星期一

程式Memo - C# HTTP POST

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Url);

ASCIIEncoding encoding = new ASCIIEncoding();
String postData = "data";
byte[] data = encoding.getByte(postData);

webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = data.Length;

Stream reqStream = webRequest.GetRequestStream();
reqStream.Write(data, 0, data.Length);

HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();

string responseStr = new StreamReader(response.GetResponseStream()).ReadToEnd();


沒有留言: