'Xamarin HttpClient request on Local network gets NameResolutionFailure error

Need to make a request with a local network server. If machine name is known, but not IP address.

string serverAddress = "mylocalserver";
System.Net.ServicePointManager.DnsRefreshTimeout = 0;
HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
HttpClient client = new HttpClient(handler);
var url = $"http://{serverAddress}/";
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();

but it fails with

System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: NameResolutionFailure



Solution 1:[1]

The NameResolutionFailure is typically a DNS name resolve error.

In general, if your server is in a domain (and configured correctly), you should be ale to reach it by it's full name:

yourlocalserver.yourdomain.local

If you don't have a domain, than you can also configure a "DNS override" in the local system. This is different per OS. For example, in windows its the host file located in %WINPATH%\System32\drivers\etc.

Third, you can have a DNS in your network without a fully configured domain. If the server is in it you should consult the DNS for the correct address.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stefan