cod*_*fun 3 localhost fiddler asp.net-web-api
我在让 fiddler 获取自托管 asp.net web api 的流量时遇到问题。我的情况可能有点不同,因为托管 Web api 的同一个应用程序也在使用它(是的,我们有理由这样做:))。我们正在使用 HttpClient。以下是我尝试过的事情:
将以下内容添加到 app.config
<system.net>
<defaultProxy>
<proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost:8888"/>
</defaultProxy>
Run Code Online (Sandbox Code Playgroud)
尝试从单独的 .net 客户端访问 api(认为使用托管它的 api 的同一进程不允许捕获流量,因为它都是进程内的)。
现在,如果我在本地打开网络浏览器或邮递员并点击 api,那么流量将被正确捕获
这是客户端代码:
var handler = new HttpClientHandler();
handler.UseProxy = true;
handler.Proxy = new WebProxy("http://127.0.0.1",8888);
var client = new HttpClient(handler) {BaseAddress = new Uri(new Uri("http://localhost:8085"), "api/companies")};
HttpResponseMessage response;
using (client)
{
response = client.GetAsync(client.BaseAddress).Result;
}
var result = response.Content.ReadAsAsync<IEnumerable<Company>>().Result;
Run Code Online (Sandbox Code Playgroud)
现在理想情况下,我希望能够在正在运行的应用程序上打开 fiddler 并捕获流量(即使在生产中),而无需更改源代码。
不幸的是,.NET Framework 被硬编码以绕过本地主机地址的代理(请参阅我的功能请求: https: //visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/6359204-support-the-loopback-代理绕过列表中的令牌)
要解决此问题,请将您的请求 URL 从 更改http://localhost:8085为http://localhost.fiddler:8085,Fiddler 将接收该请求。
| 归档时间: |
|
| 查看次数: |
983 次 |
| 最近记录: |