Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I make Fiddler capture HTTP requests made by my MVC app to my ASP.NET Web API?

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.

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?

like image 941
Water Cooler v2 Avatar asked Jul 12 '14 00:07

Water Cooler v2


People also ask

Can Fiddler capture desktop application traffic?

You can use Fiddler to create an HTTP session of the monitored web application. In Fiddler, go to Tools > Fiddler Options > HTTPS. Select Capture HTTPS CONNECTs and Decrypt HTTPS traffic. Go to File > Capture Traffic or press F12 to turn off capturing.


2 Answers

The Fiddler Docs addess this exact issue.

There are two parts to this

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

<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);

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.

like image 188
Jon P Avatar answered Oct 14 '22 12:10

Jon P


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.

like image 22
nbering Avatar answered Oct 14 '22 11:10

nbering