日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
淺析C#HTTPRequest請(qǐng)求程序模擬

C# HTTP Request請(qǐng)求程序模擬是如何實(shí)現(xiàn)的呢?我們?cè)趯?shí)現(xiàn)發(fā)送請(qǐng)求的操作是會(huì)用到哪些方法呢?那么下面我們來(lái)看看具體的實(shí)現(xiàn)方法,使用下面的代碼片段時(shí),記得 在程序的引用上右鍵,然后添加引用,添加 System.Web. 就可以使用下面的代碼了.

C# HTTP Request請(qǐng)求程序模擬實(shí)例

 
 
 
  1. using System.Net;  
  2. using System.IO;  
  3. using System.Web;  
  4.  
  5. /********************  
  6. *C# HTTP Request請(qǐng)求程序模擬***  
  7.  * 向服務(wù)器送出請(qǐng)求  
  8.  * */ 
  9. public string SendRequest(string param)  
  10. {  
  11. ASCIIEncoding encoding = new ASCIIEncoding();  
  12. byte[] data = encoding.GetBytes(param);  
  13. HttpWebRequest request =   
  14. (HttpWebRequest)HttpWebRequest.Create(this.url);  
  15. request.Method = "POST";  
  16. request.ContentType = "application/x-www-form-urlencoded";  
  17. request.ContentLength = data.Length;  
  18. Stream sm = request.GetRequestStream();  
  19. sm.Write(data, 0, data.Length);  
  20. sm.Close();  
  21.  
  22. HttpWebResponse response =   
  23. (HttpWebResponse)request.GetResponse();  
  24.  
  25. if (response.StatusCode.ToString() != "OK")  
  26. {  
  27. MessageBox.Show(response.StatusDescription.ToString());  
  28. return "";  
  29. }  
  30.  
  31. StreamReader myreader = new StreamReader(  
  32. response.GetResponseStream(), Encoding.UTF8);  
  33. string responseText = myreader.ReadToEnd();  
  34. return responseText;  
  35. }  
  36. /**C# HTTP Request請(qǐng)求程序模擬  
  37.  * 進(jìn)行UTF-8的URL編碼轉(zhuǎn)換(針對(duì)漢字參數(shù))  
  38.  * */ 
  39. public string EncodeConver(string instring)  
  40. {  
  41. return HttpUtility.UrlEncode(instring, Encoding.UTF8);  
  42. }  
  43. /**C# HTTP Request請(qǐng)求程序模擬  
  44.  * 進(jìn)行登錄操作并返回相應(yīng)結(jié)果  
  45.  * */ 
  46. public bool DoLogin(string username,   
  47. string password)  
  48. {  
  49. password = System.Web.Security.FormsAuthentication.  
  50. HashPasswordForStoringInConfigFile(password, "MD5");  
  51. string param = string.Format("do=login&u={0}&p={1}",  
  52.  this.EncodeConver(username), this.EncodeConver(password));  
  53. string result = this.SendRequest(param);  
  54. // MessageBox.Show(result); 解析 Result ,我這里是作為一個(gè)XML Document來(lái)解析的  
  55. return true;  
  56. }  

C# HTTP Request請(qǐng)求程序模擬的基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C# HTTP Request請(qǐng)求程序模擬有所幫助。


網(wǎng)站欄目:淺析C#HTTPRequest請(qǐng)求程序模擬
文章位置:http://www.5511xx.com/article/djcpisc.html