15

I'm trying to use Fiddler to help someone troubleshoot an issue with Invoke-RestMethod calls to an ASP.NET WebAPI. Unfortunately, when I call Invoke-RestMethod in PowerShell, Fiddler is not intercepting the HTTP communications.

When I use Internet Explorer to browse the root of the ASP.NET website, which is part of the same application, Fiddler intercepts traffic as expected.

Can anyone explain why Fiddler is not capturing HTTP traffic through PowerShell, and how to resolve this?

3 Answers3

18

Fiddler actually works via a proxy, and automatically sets proxy settings in IE when running. You can check this by launching fiddler and then checking "Lan Settings" under Internet Options > Connection.

Invoke-RestMethod has a -Proxy parameter you can use to point to Fiddler's proxy. I think the default is 127.0.0.1:8888 :

Invoke-RestMethod -Proxy 'http://127.0.0.1:8888' ....

Edit: Adding screenshot to confirm the answer above.

Fiddler Options

JNK
  • 63,321
  • 15
  • 122
  • 138
  • 2
    Hmmmm, while your answer is accurate, it seems that it's not capturing when I specify the `-Proxy` parameter. Were you able to test it successfully? –  Jul 24 '14 at 15:14
  • Nope I did not test since I don't have a simple test case for Invoke-RestMethod right now :) – JNK Jul 24 '14 at 15:15
  • 4
    Yes, this works: `Invoke-RestMethod -Uri 'http://blogs.msdn.com/powershell/rss.aspx' -Proxy 'http://127.0.0.1:8888'` – JNK Jul 24 '14 at 15:19
  • 2
    Edited, looks like the format of the Proxy matters! – JNK Jul 24 '14 at 15:20
  • Hmmmmm, still having trouble on my end ... investigating. –  Jul 24 '14 at 15:30
  • So, your example with the MSDN Blogs RSS feed works, but it's not capturing stuff locally ... –  Jul 24 '14 at 15:33
  • Not sure what you mean locally...we can chat if you like. – JNK Jul 24 '14 at 15:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/57931/discussion-between-trevor-sullivan-and-jnk). –  Jul 24 '14 at 15:35
  • Any conclusion on this? I'm seeing a similar issue that I use the prescribed method on a Windows 8.1 box and do not see any results in Fiddler. – Kent Fehribach Apr 14 '15 at 21:32
  • @KentFehribach maybe it's version dependent (for fiddler versions)? It works fine for me in Win 8.1 – JNK Apr 15 '15 at 12:10
  • @JNK The issue is specifically when calling to LocalHost, calling to any remote machines works as expected. – Kent Fehribach Apr 16 '15 at 18:07
  • @JNK having a similar issue. Added -Proxy to the request. This does seem to proxy through fiddler but does not display the request. Any suggestions? – AntonJ May 21 '15 at 13:54
  • I had filters set up which I needed to disable! – AntonJ May 21 '15 at 13:58
  • Rather than using `localhost` or `127.0.0.1`, use the actual local IP address like `192.168.1.25` – Peter Hahndorf Jul 05 '15 at 09:17
  • This doesn't work when I use `Invoke-WebRequest` - also tried IP address instead of localhost. – PeterX May 29 '17 at 23:51
  • this will not intercept powershell requests. I want to catch the docker pull url's but unable to do that with fiddler. Is there any other way? – It's a trap Sep 11 '17 at 08:00
1

I had a similar issue (with Powershell & Fiddler2 ) while installing NPM packages.

It worked after setting up Fiddler as a Reverse Proxy then using the command mentioned in the answer here (thanks for that JNK).

Step-by-step instructions below:

  1. Follow the steps mentioned here and write the one line FiddlerScript Rule to use Fiddler as a Reverse Proxy.

In my case it was:

if (oSession.host.toLowerCase() == "127.0.0.1:8888") oSession.host = "127.0.0.1:80";

enter image description here

  1. Then in PowerShell use the configured proxy settings:

PS F:> npm install yo -g -proxy 'http://127.0.0.1:8888'

  1. Now the PowerShell traffic should flow through Fiddler.
Karthik
  • 3,075
  • 3
  • 31
  • 61
0

I was able to get it to work by resetting the fiddler https certs (see this answer).

I had the same problem while I was testing a project and it turned that running Fiddler was the cause for this error..!!

If you are using Fiddler to intercept the http request, shut it down ...

This is one of the many causes for such error.

To fix Fiddler you may need to Reset Fiddler Https Certificates.

David Klempfner
  • 8,700
  • 20
  • 73
  • 153