簡體   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