user3378165 user3378165 - 29 days ago 13
C# Question

"The remote name could not be resolved" error when calling API from server

On my website I have some calls to an API.

In client side, with AJAX, it works perfectly but from server side (MVC and C#) I'm getting the following error:


The remote name could not be resolved 'api.website.com'


This is the code that calls the API:

JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
var data = JsonConvert.SerializeObject(email);
WebClient client = new WebClient();
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
var resp = client.UploadString(@"http://api.website.com/functions/email", data);


Any help would be very much appreciated.

Answer

As @neuhaus wrote, the problem was due to a DNS setting, once it had been fixed it worked fine.

Comments