I am creating a small web api in C#/.NET, which as some point have to request some data from an external API. When I am testing in local, on my machine, it is working perfectly.
But when It is deployed on distant web hosting (I am using Ionos/1&1 Web Windows Hosting solution), for testing my app, I get this error message from my own API:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond {ip}
Here is the code calling the API and getting the response
Uri myUri = new Uri("url", UriKind.Absolute);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
return JsonConvert.DeserializeObject<ModelOfResult>(result);
}
}
Is it a proxy issues ? Code issues ? Hosting issues ?
thanks to the support from Ionos, I manage to get a proxy to make it works, by adding this code
request.Proxy = new WebProxy({proxy}, {proxy_port});
If you have any issue, please try the solution of TheGunners, or ask for your provider to give you the proxy
Still a shame I have to ask for it, but hey, it is working now