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



试图通过控制台应用程序调用一个在不同端口(非443(上运行的简单休息点。这是我的密码。

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上运行。我该如何解决这个问题?请注意,在同一台机器上,我可以大摇大摆地运行它,甚至可以从我的gitbash中卷曲它。

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
(注意-而不是.(

我不知道为什么它没有给我一个更好的错误信息。把它贴在这里,以防对其他人有帮助。

最新更新