How can I trace the HttpClient request using fiddler or any other tool?

后端 未结 6 1101
温柔的废话
温柔的废话 2020-12-09 01:20

I am using HttpClient for sending out request to one of the web api service that I don\'t have access to and I need to trace the actual request stream getting to the server

相关标签:
6条回答
  • 2020-12-09 01:26

    IIS does not use the proxy setting in Internet Option because it runs under a different user identity (default is ApplicationPoolIdentity). @EricLaw has provided a good pointer regarding the problem of capturing traffic of IIS/ASP.NET.

    Instead of configuring IIS to use my login account, I edit web.config to force HTTPClient to use proxy, like following.

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

    Here is the detail of usage from MSDN.

    0 讨论(0)
  • 2020-12-09 01:30

    Generally speaking, simply starting Fiddler before your application is sufficient. You haven't explained what you've tried so far.

    • If it doesn't just work, read: http://fiddlerbook.com/fiddler/help/hookup.asp#Q-DOTNET
    • If your target URL is localhost or 127.0.0.1, read: http://fiddlerbook.com/fiddler/help/hookup.asp#Q-LocalTraffic
    • If your code is running in IIS or ASP.NET, read: http://fiddlerbook.com/fiddler/help/hookup.asp#Q-IIS
    0 讨论(0)
  • 2020-12-09 01:32

    If you are connecting with a url like http://localhost:1234 change it to http://localhost.fiddler:1234/ and the requests from HttpClient should then become visible in Fiddler.

    0 讨论(0)
  • 2020-12-09 01:39

    Use HttpTracer - a library built to capture Http requests/responses. You won't need to configure a proxy, it's as easy as passing an instance of the handler into HttpClient: new HttpClient(new HttpTracerHandler()). Try it out, it's been invaluable for us on the Xamarin side and for S2S purposes in ASP.NET.

    0 讨论(0)
  • 2020-12-09 01:43

    If the .NET application is running in your current user account, add the following content inside the configuration section:

    <configuration>
     <system.net>
      <defaultProxy>
       <proxy bypassonlocal="false" usesystemdefault="true" />
      </defaultProxy>
     </system.net>
    </configuration>
    

    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:

    http://mymachine/X509SignCodeService/X509SigningService.asmx

    0 讨论(0)
  • all request to IIS are logged in logging directory (iis manager > iis server > logging) default is: %SystemDrive%\inetpub\logs\LogFiles

    At the end of line there is status of the request.

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