为什么只有在我打开Fiddler时才能在ASP.NET中调用API?

我在我的索引控制器中调用这样的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(); readtask.Wait(); model = readtask.Result; }); task.Wait(); return View(model); } 

如果我关闭Fiddler我会收到以下错误:

无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8888

是否有一些我必须包含的配置,以便调用API工作,即使我没有Fiddler打开。

检查web.config是否有任何代理配置,还要检查是否已配置.net可能使用的系统默认代理。 您可以将其添加到web.config以禁用代理配置: