System.Net.Webexception: the Remote Name Could Not Be Resolved:

System.Net.WebException: The remote name could not be resolved:

It's probably caused by a local network connectivity issue (but also a DNS error is possible). Unfortunately HResult is generic, however you can determine the exact issue catching HttpRequestException and then inspecting InnerException: if it's a WebException then you can check the WebException.Status property, for example WebExceptionStatus.NameResolutionFailure should indicate a DNS resolution problem.


It may happen, there isn't much you can do.

What I'd suggest to always wrap that (network related) code in a loop with a try/catch block (as also suggested here for other fallible operations). Handle known exceptions, wait a little (say 1000 msec) and try again (for say 3 times). Only if failed all times then you can quit/report an error to your users. Very raw example like this:

private const int NumberOfRetries = 3;
private const int DelayOnRetry = 1000;

public static async Task<HttpResponseMessage> GetFromUrlAsync(string url) {
using (var client = new HttpClient()) {
for (int i=1; i <= NumberOfRetries; ++i) {
try {
return await client.GetAsync(url);
}
catch (Exception e) when (i < NumberOfRetries) {
await Task.Delay(DelayOnRetry);
}
}
}
}

System.Net.WebException remote name could not be resolved 'http'

You're calling the WebProxy(string, int) constructor - where the string is meant to be a host name, not a URI.

You should call the WebProxy(string) constructor, at which point the string is a URI. If you need to specify a non-default port, put that in the URI, e.g.

webRequest.Proxy = new WebProxy("https://10.1.1.1:12345");

ASP.NET Exception: The remote name could not be resolved: 'apiconnector.com'

I finally managed to get this working, with the help of a colleague. The problem only occurs in specific conditions, in my case, this was on my development machine as part of a company domain. The domain uses a proxy server to manage web requests/responses. It turns out that our proxy server was blocking responses from apiconnector.com hence the exception; In addition to that we had to adjust the proxy settings in Internet Explorer as this provides the default settings in Visual Studio too (when configured correctly).

I cannot specify what was changed in terms of the proxy settings, as I stated, I was helped by a colleague; he managed this part of the resolution; However that only solved half of the problem...the exception was still occurring with Visual Studio, however the addition of the following XML to the web.config file resolved everything, and now it works!

<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
</defaultProxy>
</system.net>


Related Topics



Leave a reply



Submit