C# 小工具开发--DeBugHttp
生活随笔
收集整理的這篇文章主要介紹了
C# 小工具开发--DeBugHttp
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
? ? 隨著RESTful的流行,前后端分離,我們后端開發(fā)人員在開發(fā)過程中多http相關(guān)方法進(jìn)行測(cè)試。這就是這個(gè)小工具的初衷。
? ?代碼地址:https://github.com/gdoujkzz/DebugHttp ?這是一個(gè)wpf小程序。
? ?
private string GetResponse (string method,string url,string param) {try{HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);httpWebRequest.ContentType = "application/x-www-form-urlencoded";httpWebRequest.Method = method;httpWebRequest.Timeout = 20000;if (method == "POST"){byte[] btBodys = Encoding.UTF8.GetBytes(param);httpWebRequest.ContentLength = btBodys.Length;httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);}//這里就是把httpwebrequest請(qǐng)求封裝好了HttpWebResponse httpWebResonse = (HttpWebResponse) httpWebRequest.GetResponse();string responseContent = null;using (StreamReader streamReader = new StreamReader(httpWebResonse.GetResponseStream())){//流文件的讀取。responseContent = streamReader.ReadToEnd();}httpWebRequest.Abort();httpWebResonse.Close();return responseContent;}catch (Exception ex){return ex.Message;}?
轉(zhuǎn)載于:https://www.cnblogs.com/gdouzz/p/6086141.html
總結(jié)
以上是生活随笔為你收集整理的C# 小工具开发--DeBugHttp的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 函数的递归调用(专题)
- 下一篇: C#语言实现定时开启或禁用网卡小程序