title: How to use Fiddler with HttpClient?
body: <p>I know there are many of questions/answers, blogs about this, not talking about Telerik's FAQ. Still I could not find this diagnosed and solved in a clear pure way:</p>
  
  <p><strong>Context:</strong></p>
  
  <p>I have a Web API app, and I have a (unit test) client, which uses HttpClient to send requests to the API. Web API app listens in <a href="http://localhost:8631/">http://localhost:8631/</a>
  Sometimes I use Fiddler to see what's going on.</p>
  
  <p><strong>Issue:</strong></p>
  
  <p>Traffic between my HttpClient and Web API is not captured by Fiddler. After launching Fiddler traffic is still OK, but not shown in Fiddler.</p>
  
  <p><strong>Diagnostics so far:</strong></p>
  
  <ul>
  <li><strong>Important:</strong> Using any browser and sending requests to <a href="http://localhost:8631/">http://localhost:8631/</a> <strong>is working</strong>, I mean: <strong>traffic captured by Fiddler</strong></li>
  <li>Configuring HttpClient explicitly to use Fiddler as proxy does not help. </li>
  <li>Changing HttpClient url from <a href="http://localhost:8631/">http://localhost:8631/</a> to <a href="http://localhost">http://localhost</a><strong>.fiddler</strong>:8631/ <strong>helps</strong>, regardless of proxy was configured or not.</li>
  </ul>
  
  <p><strong>Conclusions:</strong>
  At least my case: It is not about HttpClient is configured explicitly to using Fiddler as proxy or not. It is about HttpClient's and/or Fiddler's localhost behaviour.</p>
  
  <p><strong>Issue again:</strong></p>
  
  <p>One may ask: Problem solved, then what is the question? Well...</p>
  
  <p><strong>Q1:</strong> This is still a painful issue, because the url is coded or configured somewhere (I mean <a href="http://localhost:8631/">http://localhost:8631/</a> <strong>or</strong> <a href="http://localhost">http://localhost</a><strong>.fiddler</strong>:8631 so every start and stop of fiddler it must be updated. More: Checking in the source to source control, and checking out on an other machine by a teammate may cause issue. So: Is there any less painful workaround for this?</p>
  
  <p>Hard coding my machine name (which also could work) causes the very same pain and issue when working in a team and using source control</p>
  
  <p><strong>Q2:</strong> Why is this inconsistent behaviour: Pure <a href="http://localhost:8631/">http://localhost:8631/</a> works from any browser but not from HttpClient.</p>
  
  <p>I think answering Q2 can get us closer to a more usable workaround.</p>
  
  <p><strong>Code Exhibit</strong></p>
  
  <pre><code>    // Using the following url  w o r k s  regardless of any proxy setting
      // ...but it is a pain to hardcode or configure this and change    depending on Fiddler is running or not
  
      //private const string ApiUrl = "http://localhost.fiddler:8631/"; 
  
      // This is not working regardless any proxy setting. Trafic bypasses Fiddler
      private const string ApiUrl = "http://localhost:8631/";
  
      protected HttpClient GetClient()
      {
          var httpClientHandler = new HttpClientHandler
          {
              // Does not work 
              //Proxy = new WebProxy("http://localhost:8888", false),
  
              // Does not work
              Proxy = WebRequest.DefaultWebProxy,
              UseProxy = true
          };
  
  
          var client = new HttpClient(httpClientHandler)
          {
              BaseAddress = new Uri(ApiUrl)
          };
          // ...
  </code></pre>