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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With