I have the following C# code I'm trying to use to get a response from a url I can go to manually.
static void Main(string[] args)
{
Uri theRequestUriString = new Uri("<<<my_url>>>");
var request = WebRequest.Create(theRequestUriString);
request.UseDefaultCredentials = true;
WebProxy myproxy = new WebProxy("<<<my_proxy>>>:<<<my_port>>>", true);
request.Proxy = myproxy;
request.Timeout = Convert.ToInt32(TimeSpan.FromMinutes(5).TotalMilliseconds);
request.Credentials = CredentialCache.DefaultCredentials;
string textResponse;
var resp = request.GetResponse();//*****401 error here*****
using (var sr = new StreamReader(resp.GetResponseStream()))
{
textResponse = sr.ReadToEnd().Trim();
}
}
System.Net.WebException: 'The remote server returned an error: (401) Unauthorized.'
I can go there manually but get a 401 Unauthorized if I try to use this code. Shouldn't the CredentialCache take care of that? I'm using Visual Studio locally if that is not the case.
If the url is instead https://www.yahoo.com then this works just fine.