zoukankan      html  css  js  c++  java
  • C# 小工具开发DeBugHttp

        随着RESTful的流行,前后端分离,我们后端开发人员在开发过程中多http相关方法进行测试。这就是这个小工具的初衷。

       代码地址:https://github.com/gdoujkzz/DebugHttp  这是一个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请求封装好了
                    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;
                }    
  • 相关阅读:
    1015: [JSOI2008]星球大战starwar
    Tyvj P1813 [JSOI2008]海战训练
    1012: [JSOI2008]最大数maxnumber
    1430: 小猴打架
    1270: [BeijingWc2008]雷涛的小猫
    1202: [HNOI2005]狡猾的商人
    1059: [ZJOI2007]矩阵游戏
    3039: 玉蟾宫
    1303: [CQOI2009]中位数图
    1002: [FJOI2007]轮状病毒
  • 原文地址:https://www.cnblogs.com/gdouzz/p/6086141.html
Copyright © 2011-2022 走看看