title: How to make HttpClient relay traffic show up in Fidder or Charles?
body: <p>I have a simple web api project based on this example: 
  <a href="http://aspnet.codeplex.com/sourcecontrol/latest#Samples/WebApi/RelaySample/Program.cs" rel="nofollow">http://aspnet.codeplex.com/sourcecontrol/latest#Samples/WebApi/RelaySample/Program.cs</a></p>
  
  <p>However, in the above sample the relay is working with a local server, in my project the relay is working with an external web server with a real address; companyX.com </p>
  
  <p>I am using the relay service (or, web proxy service) through a browser, for example, in the browser request relayService.com/companyX. The relay service responds with data from the external companyX.com site. </p>
  
  <p>The relay works great, however some headers are not correct and I need to see what the HttpClient is sending to the remote companyX.com server. </p>
  
  <p>In fiddler or Charles, only the request/response from my browser to relayService.com is listed, the request/response from the HttpClient to relayService.com never shows up.</p>
  
  <p>The relayService.com is running locally on my machine, in IIS7, I'm using the hosts file to direct traffic to relayService.com. </p>
  
  <p>I have tried several variation of the following when creating the HttpClient:</p>
  
  <pre><code>        var clientHandler = new HttpClientHandler
          {
              CookieContainer = cookies,
              UseCookies = true,
              UseDefaultCredentials = false,
              Proxy = new WebProxy("http://localhost:8888"),
              UseProxy = true,
              AutomaticDecompression = DecompressionMethods.GZip, 
              AllowAutoRedirect = false, 
              ClientCertificateOptions = ClientCertificateOption.Automatic
          };
  
  
          HttpClient client = new HttpClient(clientHandler);
  </code></pre>
  
  <p>UPDATE</p>
  
  <p>If I change <code>UseProxy = false</code> The service continues to work, when Fiddler is open or closed.</p>
  
  <p>With <code>UseProxy = true</code> then the service will fail, if fiddler is open, I get the following error:</p>
  
  <pre><code>Object reference not set to an instance of an object.
  
  at System.DomainNameHelper.IdnEquivalent(String hostname) at System.Net.HttpWebRequest.GetSafeHostAndPort(Uri sourceUri, Boolean addDefaultPort, Boolean forcePunycode) at System.Net.HttpWebRequest.GenerateProxyRequestLine(Int32 headersSize) at System.Net.HttpWebRequest.SerializeHeaders() at System.Net.HttpWebRequest.EndSubmitRequest() at System.Net.Connection.CompleteConnection(Boolean async, HttpWebRequest request)
  </code></pre>
  
  <p>With <code>UseProxy = true</code> and fiddler is CLOSED, I get the following (obvious) error:</p>
  
  <pre><code>No connection could be made because the target machine actively refused it 127.0.0.1:8888
  </code></pre>
  
  <p>In the same solution I am using HttpWebRequest to download data from the web and that does show up in Fiddler, so it seems to be an issue with the HttpClient.GetAsync()</p>
  
  <p>I have tried this on two machines with identical results. </p>
  
  <p>I have been struggling with this all day, any help would be much appreciated. </p>
  
  <p>Just to recap:
  * relayService.com is running locally on my machine, in IIS7</p>
  
  <ul>
  <li><p>hosts file has "127.0.0.1 relayService.com"</p></li>
  <li><p>relayService.com is an MVC Web API site that uses HttpClient.GetAsync() to download content from the live web</p></li>
  <li><p>Fiddler/Charles is running locally on same machine</p></li>
  <li><p>browser traffic to the local relayService.com appears in Fiddler/Charles</p></li>
  <li><p>HttpClient.GetAsync() to live web traffic does not appear in Fiddler/Charles</p></li>
  <li><p>Fiddler/Charles are both up to date versions.</p></li>
  </ul>
  
  <p>Thanks again</p>