gpt4 book ai didi

c# - 为什么仅当我打开 Fiddler 时才能在 ASP.NET 中调用 API?

转载 作者:太空狗 更新时间:2023-10-29 17:44:47 30 4
gpt4 key购买 nike

我像这样在我的索引 Controller 中调用一个 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,我会收到以下错误:

No connection could be made because the target machine actively refused it 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>

关于c# - 为什么仅当我打开 Fiddler 时才能在 ASP.NET 中调用 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19561064/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com