I am testing an endpoint that I am experiencing some issues with.
I am simply using HttpClient
in a loop that performs a request each hour.
var httpClient = new HttpClient();
var message = httpClient.GetAsync(url).Result;
Console.WriteLine(message.StatusCode);
Once in a while I am getting this exception:
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The remote name could not be resolved: 'xxx'
The experience is that right after the exception, the URL can be accessed. In a browser you simply refresh the page and all is good.
I still haven't got any reports from users experiencing it so I am wondering if it's just a local issue here but could use a little information to help diagnose.
Is there a way to check if The remote name could not be resolved is caused by an DNS issue or by a web server issue from the exceptions? Can I get more information out of HttpCLient
or do I need more advanced diagnostic tools?
This question is related to
c#
.net
system.net.webexception
Open the hosts file located at : **C:\windows\system32\drivers\etc**.
Add the following at end of this file :
YourServerIP YourDNS
Example:
198.168.1.1 maps.google.com
I had a similar issue when trying to access a service (old ASMX service). The call would work when accessing via an IP however when calling with an alias I would get the remote name could not be resolved.
Added the following to the config and it resolved the issue:
<system.net>
<defaultProxy enabled="true">
</defaultProxy>
</system.net>
Source: Stackoverflow.com