Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why calling API in ASP.NET works only if I have Fiddler open?

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.

like image 327
mgiota Avatar asked Oct 24 '13 08:10

mgiota


1 Answers

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>
like image 117
RasmusW Avatar answered Sep 29 '22 18:09

RasmusW