Trying to call a simple rest point which is run on a different port(non-443) through a console app. 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:
<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? Note that on the same machine, I can run it through swagger or even a curl from my git bash.
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.
I had https://myrestapi.dev.company.com:9443/api/healthcheck
instead of https://myrestapi-dev.company.com:9443/api/healthcheck (Note the - instead of.)
I am not sure why it didn't give me a better error message. Posting it here in case it helps someone else.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.