我怎样才能让Fiddler将我的MVC应用程序发出的HTTP请求捕获到我的ASP.NET Web API?

时间:2022-11-16 20:13:12

I have an ASP.NET MVC app that makes request to an ASP.NET Web API using the System.Net.HttpClient class. Both the MVC app, i.e. the client, and the ASP.NET Web API, i.e. the server, are hosted in IIS Express by the Visual Studio debugger when I start debugging them.

我有一个ASP.NET MVC应用程序,它使用System.Net.HttpClient类向ASP.NET Web API发出请求。当我开始调试它们时,Visual Studio调试器将MVC应用程序(即客户端)和ASP.NET Web API(即服务器)都托管在IIS Express中。

I would like to have Fiddler capture the requests that are made by my MVC app to the ASP.NET Web API. Is this possible?

我想让Fiddler捕获我的MVC应用程序对ASP.NET Web API的请求。这可能吗?

2 个解决方案

#1


4  

The Fiddler Docs addess this exact issue.

Fiddler Docs补充了这个确切的问题。

There are two parts to this

这有两个部分

1 Set the MVC app to use fiddler as a proxy either in the web.config

1将MVC应用程序设置为在web.config中使用fiddler作为代理

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

Or in code: GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888);

或者在代码中:GlobalProxySelection.Select = new WebProxy(“127.0.0.1”,8888);

2 Reference your api by machine name instead of localhost. This is because .net by default will not use a proxy when referencing something via localhost.

2按机器名称而不是localhost引用api。这是因为.net默认情况下在通过localhost引用某些内容时不会使用代理。

#2


2  

The .NET Framework is hard-coded not to pass traffic to localhost through proxies. Try using http://localhost.fiddler:xxxx/. This should route your request through fiddler so that it can capture the traffic. See Fiddler Documentation on this problem for more details and a couple other address options.

.NET Framework是硬编码的,不通过代理将流量传递给localhost。尝试使用http://localhost.fiddler:xxxx /。这应该通过fiddler路由您的请求,以便它可以捕获流量。有关更多详细信息和其他几个地址选项,请参阅有关此问题的Fiddler文档。

#1


4  

The Fiddler Docs addess this exact issue.

Fiddler Docs补充了这个确切的问题。

There are two parts to this

这有两个部分

1 Set the MVC app to use fiddler as a proxy either in the web.config

1将MVC应用程序设置为在web.config中使用fiddler作为代理

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

Or in code: GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888);

或者在代码中:GlobalProxySelection.Select = new WebProxy(“127.0.0.1”,8888);

2 Reference your api by machine name instead of localhost. This is because .net by default will not use a proxy when referencing something via localhost.

2按机器名称而不是localhost引用api。这是因为.net默认情况下在通过localhost引用某些内容时不会使用代理。

#2


2  

The .NET Framework is hard-coded not to pass traffic to localhost through proxies. Try using http://localhost.fiddler:xxxx/. This should route your request through fiddler so that it can capture the traffic. See Fiddler Documentation on this problem for more details and a couple other address options.

.NET Framework是硬编码的,不通过代理将流量传递给localhost。尝试使用http://localhost.fiddler:xxxx /。这应该通过fiddler路由您的请求,以便它可以捕获流量。有关更多详细信息和其他几个地址选项,请参阅有关此问题的Fiddler文档。