Hello I am having a bit of trouble trying to read data off of a https
URL.
When I try to access the site with the code below I get a 401
Unauthorized
error code.
I have spoken with the server admin and he
investigated and found out that I
am getting a 401.1 error which indicates
that the login info I passed via
credentials is invalid.
I am not sure
why this is because I am putting the correct login information
and I verify
this by accessing the site via the browser and using the same
login
info.
Is there a reason that the login info data is not being sent properly
to the
server for authentication?
I have tried fixing this for a while
and I did a bit of research on it and
cannot find any answers.
If
anyone has some info or advice I would greatly appreciate it.
I put my
test code below:
try
{
HttpWebRequest webRequest =
(HttpWebRequest)
WebRequest.Create(new Uri("
https://mysite.com/test.html"));
NetworkCredential creds = new NetworkCredential("myuserid", "mypassword",
"mydomain");
webRequest.Credentials = creds;
webRequest.Method = "GET";
// setup request stream
HttpWebResponse webResp = (HttpWebResponse)webRequest.GetResponse(); //
401
unauthorized error exception
Console.WriteLine(webResp.StatusCode);
Console.WriteLine(webResp.Server);
Stream answer =
webResp.GetResponseStream();
StreamReader _answer = new
StreamReader(answer);
Console.WriteLine(_answer.ReadToEnd());
}
catch (WebException
wEx)
{
Console.WriteLine("Debug Message: " +
wEx.Message);
}