Visual Studio 2012, IIS Express, and Fiddler

From the mail bag...

Q:When I use IE10 on Windows 8 to visit an IIS Express instance using the following URL http://ipv4.fiddler:2468/, I get an unexpected error message.

HTTP/1.1 400 Bad Request
Content-Type: text/html;charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Wed, 22 Aug 2012 19:59:52 GMT
Connection: close
Content-Length: 334

<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Hostname</h2>
<hr><p>HTTP Error 400. The request hostname is invalid.</p></BODY></HTML>

What's up with that?

A: First, it's important to understand that you don’t need to use any special “.fiddler” addresses for Fiddler to capture local traffic when using IE (since version 9). You only need to use those when your client is making its HTTP requests using System.Net (e.g. HTTPWebRequest), which unconditionally bypasses the proxy for addresses it deems "local."

Having said that, you'll find that the same request works if you use the address http://localhost.fiddler:2468/. The reason that localhost.fiddler works is that when Fiddler gets this URL, it sets the request's Host header to “localhost” before passing it to the IIS Express server. If you instead use ipv6.fiddler as the request URL's hostname, Fiddler sets the Host header to “[::1]”. If you use ipv4.fiddler, Fiddler sets the Host header to “”.

IIS Express only expects the “localhostHost header value and returns the HTTP/400 for the “” Host, saying, in effect “I don’t have a website with that hostname.


Comments (1)

  1. PeterK says:

    I can't get this to work with HttpClient. I've created a WebRequestHandler.Proxy that explicitly does not bypass localhost.fiddler, but the request fails anyway with the error "unable to resolve localhost.fiddler"

    EricLaw: This indicates that you haven't set the proxy properly. Please post a sample of your code on StackOverflow with the Fiddler keyword. Thanks!

Skip to main content