Is there a way to configure Fiddler to intercept HTTP calls from a Windows service?

前端 未结 5 1311
梦如初夏
梦如初夏 2021-02-01 06:44

We\'re in the process of replacing an old (5+ years) Windows service application built with VS2005 that makes an HTTP GET call. There are several things that make this difficul

相关标签:
5条回答
  • 2021-02-01 06:52

    Codeka provided a clue to get me going in the right direction. The piece that was still missing was how to get the proxy configured. The <appname>.exe.config needed to have a section like the following added:

    <system.net>
            <defaultProxy enabled="true">
                    <proxy proxyaddress="http://127.0.0.1:8888" bypassonlocal="False"/>
            </defaultProxy>
    </system.net>
    

    Once this was done the Windows service's http traffic started flowing through Fiddler.

    0 讨论(0)
  • 2021-02-01 07:04

    And, of course, if Fiddler doesn't work there's always Wireshark. As a hint, use a couple filters in Wireshark (e.g. show only packets going to or coming from the destination IP) to avoid feeling like you're being overrun with data.

    0 讨论(0)
  • 2021-02-01 07:08

    Fiddler just acts as an HTTP proxy, so if you can configure a proxy in your service then you can configure it to go through Fiddler. Whether that's possible is hard to say...

    If that doesn't work, you could do it by running Fiddler on a second computer and configuring it to listen on port 80. Then on your "test" computer, edit your hosts file so that it points to the second computer instead. So say the web service is on www.example.com, you set up your test server so that "www.example.com" points to your second computer (running Fiddler). Then, when the service goes to connect to "www.example.com" it'll actually connect to Fiddler. Fiddler will then forward the connection to the real www.example.com after recording the request/response.

    I haven't tested the above, but I think it would work. Obviously, if you can configure the proxy settings in your service that would be easier!

    0 讨论(0)
  • 2021-02-01 07:13

    As .NET bypasses proxies for localhost and 127.0.0.1, just hardcode your machine name instead for the url you're testing with.

    //myUrl = "http://127.0.0.1/myservice";
    myUrl = "http://mymachine/myservice";
    
    0 讨论(0)
  • 2021-02-01 07:16

    Note: Important: Regardless of other settings, .NET will always bypass the Fiddler proxy for URLs containing localhost. So, rather than using localhost, change your code to refer to the machine name. For instance:

    This URL will not appear in Fiddler:

    http://localhost/X509SignCodeService/X509SigningService.asmx This URL will appear in Fiddler:

    0 讨论(0)
提交回复
热议问题