9

I am calling an API in my Index Controller like this and everything works fine, only if I have Fiddler open.

public ActionResult Index()
{
    Base model = null;
    var client = new HttpClient();
    var task =
        client.GetAsync(
        "http://example.api.com/users/john/profile")
        .ContinueWith((taskwithresponse) =>
        {
            var response = taskwithresponse.Result;
            var readtask = response.Content.ReadAsAsync<Base>();
            readtask.Wait();
            model = readtask.Result;
        });
    task.Wait();

    return View(model);
}

If I close Fiddler I get following error:

No connection could be made because the target machine actively refused it 127.0.0.1:8888

Is there some configuration I have to include, so that calling an API works, even if I don't have Fiddler open.

Kara
  • 6,115
  • 16
  • 50
  • 57
mgiota
  • 203
  • 1
  • 4
  • 13
  • 3
    127.0.0.1:8888 is your fiddler proxy address. Somehow, somewhere your ASP.Net application is still using your fiddler proxy as its http proxy. Figure out where, and turn it off. It may just require you to restart IIS. – Aron Oct 24 '13 at 08:45
  • Yes you are right. I used the solution proposed by RasmusW, and it worked. – mgiota Oct 24 '13 at 11:31

1 Answers1

12

Check web.config for any proxy configuration, and also check whether you have configured a system default proxy which .net might use. You can add this to your web.config to disable proxy configuration:

    <system.net>
      <!-- set enabled to true to use the system default proxy -->
      <defaultProxy enabled="false" />
    </system.net>
RasmusW
  • 3,355
  • 3
  • 28
  • 46
  • Thank you. I did this, but then I just wanted to know where is this proxy setup. Because my Internet explorer settings do not point to any proxy. Found it in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config, I deleted it from there and everything worked just fine. I think Fiddler has added this, because I don't remember adding it at all! ... Hope this will not break any fiddler features! – A Khudairy Apr 04 '17 at 07:50
  • I don't think that Fiddler adds it to machine.config. Actually, the Fiddler blog has an entry about [how to add it manually](http://www.telerik.com/blogs/capturing-traffic-from-.net-services-with-fiddler). – RasmusW Apr 04 '17 at 15:41