Hold on. before you mark this as duplicate. I am having a slightly different issue.
So I'm calling an api that throws this exception. But - the catch is This happens only when the call is made from server. If i make an angular /ajax call - this works perfectly fine.
Where as in .net when I write the following
using (HttpClient hc = new HttpClient())
hc.BaseAddress = new Uri(endpoint);
HttpResponseMessage response = hc.GetAsync(url).Result;
So i finally i figured what the reason was - but i am not sure why it happens.
The reason is because - Visual studio was not honoring our proxy settings. Essentially - we are talking about 3 servers here
So my machine ip : xxx.xx.xx.1
Our Company Proxy server ip : xx.xx.xx.2
The api ip : xxx.xx.xx.3 url(api.com)
Every call is routed through our proxy that i can see in my internet settings. So when i installed wireshark and saw the route --> When i access from visual studio it directly tries to access api server from my host machine without going via the proxy.
that is: xxx.xx.xx.1 --> xxx.xx.xx.3 [Failed]
Where as when i try from browser - it honors the proxy setting
that is : xxx.xx.xx.1 --> xxx.xx.xx.2
[Success] xxx.xx.xx.2 --> xxx.xx.xx.3 [Success]
The fix was - When i added the host entry to saying
xxx.xx.xx.2 - api.com
things started working - because all calls to the api were now routed via the proxy server. I dont know why this is happening or how to avoid this. atleast solved my issue.
I checked for setting- i dont have anything in my web.config / machine.config.