繁体   English   中英

无法使用 httpClient 调用具有非 443 端口的 rest 端点

[英]Unable to call rest endpoint with non-443 port with a httpClient

尝试通过控制台应用程序调用在不同端口(非 443)上运行的简单 rest 点。 这是我的代码。

using (var httpClient = new HttpClient())
{
    string url = "https://myrestapi.company.com:9443/api/healthcheck";
    using (var response = await httpClient.GetAsync(url))
    {
        string apiResponse = await response.Content.ReadAsStringAsync();
        Console.WriteLine(apiResponse);
    }
}

我尝试通过 Visual Studio 运行它并直接运行 exe,但出现错误:

<big>Access Denied (connect_method_denied)</big>
<FONT face="Helvetica">
Your request attempted a CONNECT to a port "9443" that is not permitted by default.
</FONT>
This is typically caused by an HTTPS URL that uses a port other then the default of 443.
</FONT>

我在 Windows 10 和 VS 2019 上运行。我该如何解决这个问题? 请注意,在同一台机器上,我可以通过 swagger 甚至是 curl 从我的 git ZD57469ZBB40C94988Z 运行它

curl -X GET --header 'Accept: application/json' 'https://myrestapi.company.com:9443/api/healthcheck'

我意识到这是因为我击中的 url 是错误的。

我有https://myrestapi.dev.company.com:9443/api/healthcheck

而不是https://myrestapi-dev.company.com:9443/api/healthcheck (注意 - 代替。)

我不确定为什么它没有给我更好的错误信息。 把它贴在这里以防它帮助别人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM