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;
                }    
  • 相关阅读:
    jQuery技巧大放送
    网页挂马工作原理完全分析
    C#常见问题
    网站优化之页面优化
    SQL大全分享
    获得本机的可用的所有打印机
    C#文件操作方法大全
    编程范式及其代表语言
    23种模式简說
    C# Open Source
  • 原文地址:https://www.cnblogs.com/gdouzz/p/6086141.html
Copyright © 2011-2022 走看看