[C#]發送POST Request
轉載自:http://blog.breakn.net/article.asp?id=286
- string strId = "guest";
- string strPassword= "123456";
-
- ASCIIEncoding encoding=new ASCIIEncoding();
- string postData="userid="+strId;
- postData += ("&password="+strPassword);
-
- byte[] data = encoding.GetBytes(postData);
-
- // Prepare web request...
- HttpWebRequest myRequest =
- (HttpWebRequest)WebRequest.Create("http://www.here.com/login.asp");
-
- myRequest.Method = "POST";
- myRequest.ContentType="application/x-www-form-urlencoded";
- myRequest.ContentLength = data.Length;
- Stream newStream=myRequest.GetRequestStream();
-
- // Send the data.
- newStream.Write(data,0,data.Length);
- newStream.Close();
-
- // Get response
- HttpWebResponse myResponse=(HttpWebResponse)myRequest.GetResponse();
- StreamReader reader = new StreamReader(response.GetResponseStream(),Encoding.Default);
- string content = reader.ReadToEnd();
留言
張貼留言