我在索引控制器中调用 API,就像这样,一切正常,只要我打开 Fiddler。
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);
}
如果我关闭 Fiddler 我会收到以下错误:
由于目标机器主动连接,无法建立连接
拒绝 127.0.0.1:8888
是否需要包含一些配置,以便即使我没有打开 Fiddler,调用 API 也能正常工作。
检查 web.config 中的任何代理配置,并检查您是否配置了 .net 可能使用的系统默认代理。
您可以将其添加到 web.config 以禁用代理配置:
<system.net>
<!-- set enabled to true to use the system default proxy -->
<defaultProxy enabled="false" />
</system.net>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)