Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fiddler not seeing API calls from C# HttpClient()

I have an ASP.NET MVC website that is calling a Web API web service.

The calls are working and return 200 OK - both calls to the web service on my local machine AND on a web server.

I have Fiddler running but it is not seeing these calls - only calls to the MVC website (which in turn calls the web service).

How can I see the actual web service calls?

This should be working right? Especially to the web-based web service.

I have stopped referencing http://localhost and am using MACHINENAME instead - as recommended in some SO posts. But this doesn't help.

I'm using HttpClient to call it:

using (var client = new HttpClient())
{
    var byteArray = Encoding.ASCII.GetBytes(username + ":" + password);
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

    client.BaseAddress = new Uri("http://MACHINENAME");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    var response = await client.PutAsJsonAsync("api/path", custImp);
}

How can I view the web service calls in Fiddler?

like image 389
niico Avatar asked Mar 22 '17 16:03

niico


People also ask

How do I use Fiddler to capture API calls?

Run fiddler to start capturing web requests/response made by various client applications on your system (e.g. Curl, Chrome, Internet Explorer). To start/stop capture go to File > Check/Uncheck [Capture Traffic] option. By default when you run Fiddler it behaves as default proxy server on your system.

Why is Fiddler not capturing traffic?

You should verify that Fiddler is set as a system proxy (when capturing is turned on) and that you have the administrative rights to update the OS system proxy, that the application you are monitoring is using the system proxy (and if not that it is explicitly set to use the Fiddler proxy), that you have enabled ...


1 Answers

When you start Fiddler, it will change the default system proxy for the current Windows user, so that web requests made by this user are captured by Fiddler.

However, the website runs inside IIS and runs under a different user. You have to make your website use Fiddler by explicitly specifying Fiddler as the web proxy in the web.config file of your MVC application like this (use the port that your Fiddler uses):

<configuration>
...
<system.net>
  <defaultProxy>
    <proxy  proxyaddress="http://127.0.0.1:8888" />      
  </defaultProxy>
</system.net>
...
</configuration>

References:

  • Debugging Http or Web Services Calls from ASP.NET with Fiddler
  • Capturing Traffic from .NET Services with Fiddler

As BornToCode mentions, it is also possible alternatively to change the application pool identity to your current user.

like image 160
NineBerry Avatar answered Sep 24 '22 02:09

NineBerry