HttpWebRequest with SSL URI

D

Durango2008

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);

}
 
D

Durango2008

Peter Duniho said:
Durango2008 said:
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. [...]

Are you sure you need to set the Domain of the NetworkCredential? If so,
are you sure you're using the correct domain?


I have tried both with domain and without domain.
I am putting the domain in that I use regularly to login to that page via a
web browser.

For example when I put the URL into my webbrowser an authentication screen
pops up.

In the username section I put: domain\username
than I put password in the password section and I am able to access the
page.

In the code I put "username", "password", and "domain" in the same manner as
I have previously done.
 
R

RayLopez99

Other than that, I don't really know.  Without access to a server with
the specific configuration you're dealing with, it's not a problem that
can be easily reproduced outside of your own setup.  Maybe someone else
will find the problem familiar.

I agree. It could be anything. Typically some attribute in the
web.config file is set improperly.

RL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top