为什么在ASP.NET中调用API仅如果我有小提琴手开? [英] Why calling API in ASP.NET works only if I have Fiddler open?
问题描述
我打电话在我的指数控制器这样一个API,一切工作正常,只有当我有小提琴手开放。
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:
无法连接,因为目标机器积极地进行
拒绝了127.0.0.1:8888
No connection could be made because the target machine actively refused it 127.0.0.1:8888
有一些配置我必须包括,让调用API的作品,即使我没有提琴手打开。
Is there some configuration I have to include, so that calling an API works, even if I don't have Fiddler open.
推荐答案
检查web.config中任何代理配置,并检查是否配置有哪些.NET可能使用系统默认代理。
您可以将它添加到你的web.config禁用代理配置:
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>
这篇关于为什么在ASP.NET中调用API仅如果我有小提琴手开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!