简体   繁体   English

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

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

Trying to call a simple rest point which is run on a different port(non-443) through a console app.尝试通过控制台应用程序调用在不同端口(非 443)上运行的简单 rest 点。 This is my code.这是我的代码。

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);
    }
}

I tried to run it through Visual Studio and also directly running the exe, but I get an error:我尝试通过 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>

I am running on Windows 10 and VS 2019. How do I fix this?我在 Windows 10 和 VS 2019 上运行。我该如何解决这个问题? Note that on the same machine, I can run it through swagger or even a curl from my git bash.请注意,在同一台机器上,我可以通过 swagger 甚至是 curl 从我的 git ZD57469ZBB40C94988Z 运行它

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

I realized that it was because the url I was hitting was wrong.我意识到这是因为我击中的 url 是错误的。

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

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

I am not sure why it didn't give me a better error message.我不确定为什么它没有给我更好的错误信息。 Posting it here in case it helps someone else.把它贴在这里以防它帮助别人。

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

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