I’m trying to connect to a https REST service using C# as the client code. I can POST and GET from the service using POSTMAN but in order to do that I have to setup proxy settings specifying the company’s proxy address, user ID and password in POSTMANs settings. The C# code is .net 4 and I am using HttpClient in order to call the https service. However, I get Unable to connect to remote server. It’s not clear what the error is caused by. I am running the C# code as an ASP.NET app locally on my desktop as http://localhost calling across to the https service on the company network. So, is it the case because it is https I have to have a certificate for the https service installed locally and referenced in the client code? Or is it more likely to need something like what is setup in POSTMAN related to proxy in my C# code.
Sample code below:
public async Task RunAsync()
{
// Not real url
string url = "https://blah blah";
HttpResponseMessage httpResponse = await GetAsync(url);
}
public async Task<HttpResponseMessage> GetAsync(string uri)
{
HttpClient httpClient = new HttpClient();
HttpResponseMessage content = await httpClient.GetAsync(uri);
return await Task.Run(() => content);
}
Results from Exception thrown: InnerException = {"Unable to connect to the remote server"} Message = "An error occurred while sending the request." HResult -2146233088