国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
淺析C# HTTP Request請求程序模擬 - 51CTO.COM
    C# HTTP Request請求程序向你演示了在向服務(wù)器發(fā)送請求的模擬過程,那么具體的使用到的方法是什么呢?操作步驟是什么呢?那么本文就向你介紹詳細(xì)的內(nèi)容。

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

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

            
    1. using System.Net;  
    2. using System.IO;  
    3. using System.Web;  
    4.  
    5. /********************  
    6. *C# HTTP Request請求程序模擬***  
    7.  * 向服務(wù)器送出請求  
    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請求程序模擬  
    37.  * 進(jìn)行UTF-8的URL編碼轉(zhuǎn)換(針對漢字參數(shù))  
    38.  * */ 
    39. public string EncodeConver(string instring)  
    40. {  
    41. return HttpUtility.UrlEncode(instring, Encoding.UTF8);  
    42. }  
    43. /**C# HTTP Request請求程序模擬  
    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來解析的  
    55. return true;  
    56. }  

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

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
java遍歷http請求request的所有參數(shù)
HttpWebRequest向路由器提交基本身份驗(yàn)證
Spring Cloud Feign設(shè)計(jì)原理
用JSP+Servlet+JavaBean實(shí)現(xiàn)MVC設(shè)計(jì)模式的流程
jsp設(shè)置JavaBean屬性值的動(dòng)作jsp:setProperty
在C#用HttpWebRequest中發(fā)送GET/HTTP/HTTPS請求
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服