.NET Framework 4.7 C# WebForms
This is a mystery to me and I've dug around and cannot find anything like this exact situation. This is an enterprise application running on an intranet. I am trying to call an external, third party service. It works once for every app I test it in and then I get: WebException: The remote name could not be resolved: 'xxx' every time after that. Both of the below attempts end in the same result.
This is one version of the call:
Uri uri = new Uri($"https://pesky.host.net/stuff/more/andMore%2FParam%2Fparam/action")
HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
request.Headers.Add("Accept-Encoding", "base64");
request.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(ConfigurationManager.AppSettings["ApiKey-"]);
request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(data, 0, data.Length); // Send the data.
newStream.Close();
var response = (HttpWebResponse)request.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
password = sr.ReadToEnd();
}
return password;
This is another version of the call:
HttpClient Client = new HttpClient();
Client.DefaultRequestHeaders.Add("Accept-Encoding", "base64");
try
{
HttpResponseMessage? request = new HttpResponseMessage();
Uri uri = new Uri($"https://pesky.host.net/stuff/more/andMore%2FParam%2Fparam/action");
var authBody = new StringContent(ConfigurationManager.AppSettings["ApiKey-" + copApplEnv]);
request = await Client.PostAsync(uri, authBody);
if (request != null && request.IsSuccessStatusCode)
{
var response = await request.Content.ReadAsStringAsync();
return response;
}
...
I've tried the top 3 answers here I've checked Firewall records and the first call shows going through. The others are not even hitting the logs. We have other apps that call external services in both of the methods above without trouble.
Postman and a Console app work without fail every time. What is going on? Is it my local IIS? Is it some file I don't know about?