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?
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
Configure a .NET application to use Fiddler?
If you're coding a .NET application, K Scott Allen's blog shows a simple way to hook Fiddler temporarily for debugging purposes:
GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888);
Note that you might not even need to do this-- The Framework should autodetect the WinINET proxy when the .NET application starts. Note that this means that Fiddler must be started BEFORE your application if your application is to autodetect Fiddler.
You may specify a proxy inside the yourappname.exe.config file. If the .NET application is running in your current user account, you can simply add the following content inside the configuration section:
<configuration>
<system.net>
<defaultProxy>
<proxy bypassonlocal="false" usesystemdefault="true" />
</defaultProxy>
</system.net>
</configuration>See http://msdn.microsoft.com/en-us/magazine/cc300743.aspx for more on this topic.
If you need to get code running in a different user-account (e.g. a Windows Service) to send traffic to Fiddler, you will need to edit the configuration inside the machine.config.
<!-- The following section is to force use of Fiddler for all applications, including those running in service accounts --> <system.net>
<defaultProxy>
<proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888" usesystemdefault="false" />
</defaultProxy>
</system.net>If all else fails, you can manually specify the proxy on an individual WebRequest object, like so:
objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Proxy= new WebProxy("127.0.0.1", 8888);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:
Does not show in Fiddler: http://localhost/X509SignCodeService/X509SigningService.asmx
Shows in Fiddler: http://mymachine/X509SignCodeService/X509SigningService.asmx
Using a proxy with .NET 4.5 HttpClient
This code worked for me:
var httpClientHandler = new HttpClientHandler
{
Proxy = new WebProxy("http://localhost:8888", false),
UseProxy = true
}
Note that I am not supplying an empty array to my WebProxy
constructor. Perhaps that's the problem?
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-09-02 How to Publish a NuGet Package
2015-09-02 Three ways to do WCF instance management
2015-09-02 WCF Concurrency (Single, Multiple, and Reentrant) and Throttling