Click here to Skip to main content
15,445,560 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to request a website in my application.
Authentication required for this website when i request it via IE.
i have the id and pw. how can i request it via code?


Authentication 


the login area is not a form build using html. it is a windows popup Authentication window.


What I have tried:

string authenticationUrl = @"https://xxx"; // it'use https, not sure if this impact anything.
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(authenticationUrl);
            req.Credentials = new NetworkCredential("id", "pw");
            using (WebResponse wr = req.GetResponse())
            {
                //error here: Authentication failed because the remote party has closed the transport stream.
            }
Posted
Updated 19-Apr-18 5:16am
v2
Comments
F-ES Sitecore 19-Apr-18 10:55am    
It depends on how the website implements its security.
Ziee-M 19-Apr-18 10:56am     CRLF
First, you have to get permission from the website to do. they can help you if they have for exemple an authentication service. You did not mention what you are using (winforms, WPF, maybe web ?). You should probably use a webbrowser, and create an automated logic to login. webbrowser PageLoaded => fill authentication textboxes => simulate connection button.
F-ES Sitecore 19-Apr-18 11:40am     CRLF
If it's using basic auth (the popup) see if this helps https://stackoverflow.com/questions/4334521/httpwebrequest-using-basic-authentication?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa If not google "httpwebrequest basic authentication" for lots more suggestions.

1 solution

You can create a HTTP web request object with credentials (google is your friend). What you do with the response is up to you.
 
Share this answer
 
v2
Comments
Ziee-M 19-Apr-18 11:19am    
You can't login using webrequests. And even if possible, you lose the context once you are connected, thus in your next request, you have to reconnect.
#realJSOP 19-Apr-18 14:30pm    
Wrong, and wrong. I've done it, and I found out how to using google.
Ziee-M 19-Apr-18 14:51pm     CRLF
I insist, it will not work for any website if the parameters (log, pass) are not passed in the url. Your solution will not work for google.com or facebook for example.
Richard Deeming 19-Apr-18 15:57pm     CRLF
If the authentication scheme is one of Digest, Negotiate, Kerberos, NTLM, or Basic, then John is correct. Setting the Credentials[^] property will work perfectly. NB: Neither Google nor Facebook use any of those authentication schemes. Any site where you have to type your credentials into the page itself will not work with the Credentials property. But the OP specifically said that's not the case.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900