代码之家  ›  专栏  ›  技术社区  ›  Fung

获取使用HttpWebRequest/HttpWebResponse发出的HTTP请求和响应,以在Fiddler中显示

  •  40
  • Fung  · 技术社区  · 17 年前

    3 回复  |  直到 17 年前
        1
  •  42
  •   CraigTP    17 年前

    您基本上通过Fiddler路由HTTP流量(即使用Fiddler作为代理)。


    Fiddler Web Debugging - Configuring Clients

    这反过来又链接到这里:
    Take the Burden Off Users with Automatic Configuration in .NET

    您可以通过web.config文件中的一些配置设置(对于ASP.NET应用程序)来实现这一点,如下所示:

    <system.net>
      <defaultProxy>
        <proxy
          proxyaddress="http://[your proxy address and port number]"
          bypassonlocal="false"
        />
      </defaultProxy>
    </system.net>
    

    看 here <defaultProxy>

    或者,您可以在代码中使用WebProxy对象,例如:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("[ultimate destination of your request]");
    WebProxy myproxy = new WebProxy("[your proxy address]", false);
    request.Proxy = myproxy;
    request.Method = "GET";
    HttpWebResponse response = (HttpWebResponse) request.GetResponse();
    

    看 here

    另请注意Fiddler常见问题解答中提到的重要“警告”:

    http://localhost 或 http://127.0.0.1 ?
    硬编码为不发送请求

    http://localhost:8081/mytestpage.aspx , http://machinename:8081/mytestpage.aspx .

    …或者,如果您使用的是Fiddler v2.1.8 或者稍后,只需使用 http://ipv4.fiddler 在IPv4适配器上点击localhost, 或使用 http://ipv6.fiddler IPv6适配器上的localhost。这 工作室测试Web服务器(代号: 卡西尼),因为只有测试服务器 在IPv4环回适配器上侦听。

    文件如下:

        static function OnBeforeRequest(oSession:Fiddler.Session)
        {
          if (oSession.HostnameIs("MYAPP"))
          {
            oSession.host = "127.0.0.1:8081";
          }
        }  
    

    …然后就撞了 http://myapp ,这将作为

        2
  •  11
  •   RichieHindle    17 年前

    如果你不能, Wireshark 是一个在网络硬件级别工作的类似工具,因此它可以捕获来自任何应用程序的网络流量。

    Wireshark比Fiddler更复杂,也更通用,但它是一个很好的工具箱工具,值得花点时间研究。

        3
  •  4
  •   Richard    9 年前

    如果您能够修改请求URI,并且 localhost localhost.fiddler .

    这不依赖于设置代理(无论是否设置 HttpWebRequest.Proxy 或 <defaultProxy> .config 文件)。

    this question .)