[C#]發送POST Request

轉載自:http://blog.breakn.net/article.asp?id=286
  1.     string strId = "guest"; 
  2.     string strPassword= "123456"; 
  3.     
  4.     ASCIIEncoding encoding=new ASCIIEncoding(); 
  5.     string postData="userid="+strId; 
  6.     postData += ("&password="+strPassword); 
  7.     
  8.     byte[] data = encoding.GetBytes(postData); 
  9.     
  10.     // Prepare web request... 
  11.     HttpWebRequest myRequest = 
  12.     (HttpWebRequest)WebRequest.Create("http://www.here.com/login.asp"); 
  13.     
  14.     myRequest.Method = "POST"; 
  15.     myRequest.ContentType="application/x-www-form-urlencoded"; 
  16.     myRequest.ContentLength = data.Length; 
  17.     Stream newStream=myRequest.GetRequestStream(); 
  18.     
  19.     // Send the data. 
  20.     newStream.Write(data,0,data.Length); 
  21.     newStream.Close(); 
  22.     
  23.     // Get response 
  24.     HttpWebResponse myResponse=(HttpWebResponse)myRequest.GetResponse(); 
  25.     StreamReader reader = new StreamReader(response.GetResponseStream(),Encoding.Default); 
  26.     string content = reader.ReadToEnd();  

留言

本月最夯

偷用電腦,怎知?事件檢視器全記錄!(開機時間、啟動項時間...)

[Chrome] 不用任何擴充功能,Chrome 內建開發者工具讓您輕鬆下載任何影片!