简体   繁体   中英

Using Fiddler as proxy for HttpWebRequest requires Fiddler to be running

I have a web application that I'm developing that makes a lot of HttpWebRequests. In order to make debugging them easier, I've set up the following in my web.config;

<system.net>
     <defaultProxy>
         <proxy proxyaddress="http://127.0.0.1:9999" />
      </defaultProxy>
</system.net>

This allows all of my HttpWebRequests to proxy through Fiddler. The problem is I need to have Fiddler running in order to have my app work correctly.

Ideally, I would like to have it proxy through Fiddler when Fiddler is running, and not proxy at all when Fiddler is not running without having to change my web.config each time.

There are a few options.

First, you can set the relevant Proxy property of the relevant objects inside your code directly instead of falling back to the configuration XML; you can then selectively control the use of the proxy based on any factor you like.

Alternatively, you could try setting the scriptLocation attribute to point at http://localhost:8888/proxy.pac and use Fiddler's about:config to set fiddler.proxy.pacfile.usefileprotocol to false and tick the Tools > Fiddler Options > Connections > Use PAC Script box.

Have you considered an another approach, by enabling trace listeners on System.Net? It is not as comfortable as using Fiddler, but it might be enough for sporadic debugging. For message logging, just System.Net should be sufficient, but there are more.

  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.Net">
        <listeners>
          <add name="System.Net"/>
        </listeners>
      </source>
      <!--<source name="System.Net.Sockets">
        <listeners>
          <add name="System.Net"/>
        </listeners>
      </source>-->
      <!--<source name="System.Net.Cache">
        <listeners>
          <add name="System.Net"/>
        </listeners>
      </source>-->
    </sources>
    <sharedListeners>
      <add
          name="System.Net"
          type="System.Diagnostics.TextWriterTraceListener"
          initializeData="System.Net.trace.log"
        />
    </sharedListeners>
    <switches>
      <add name="System.Net" value="Verbose" />
      <add name="System.Net.Sockets" value="Verbose" />
      <add name="System.Net.Cache" value="Verbose" />
    </switches>
  </system.diagnostics>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM