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

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

问题

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 from my client. Is there a way I can hookup the Fiddler to listen to the requests?

I am using the System.Net.Http.HttpClient class for sending out request.

Update: trying to improve this question now as I could not get what I was looking for. I am using a .Net Client application to connect to a Web Service hosted on my own IIS over HTTP channel. I have done the fiddler debugging earlier with a Website hosted on my IIS and watching the traffic generated between my browser and the WebSite. But when it comes to watching the traffic generated by a .Net client program talking to the web service using HttpClient class, strangely the fiddler does not seem to be able to tap that traffic and does not show anything. Is .Net HttpClient bypassing the WinInet API to connect to the service which results in the fiddler not able to watch the traffic?

 

回答1

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.

And the reason seem to be explained here - Microsoft inserted in their code a check and if it's "localhost" they simply skip the proxy so requests doesn't go through fiddler. Nov 6, 2017 at 15:47
 

回答2

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

 

回答3

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.

 

回答4

4

 

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

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(28)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-05-18 Math.NET Numerics Matrices and Vectors
2021-05-18 SQL Server Profiler - Why are some calls RPC:Completed and Some Calls SQL:BatchCompleted
2020-05-18 npm-package.json
2020-05-18 What is the difference between npm install and npm run build?
2020-05-18 :checked Selector
2020-05-18 Attribute Equals Selector [name=”value”]
2018-05-18 innerxml and outerxml
点击右上角即可分享
微信分享提示