简体   繁体   中英

enter webpage authentication with webclient that's not overloaded in “System.Net.NetworkCredential” in c#

I'm trying to connect and download website content that requires an authentication that is not "overloaded".

The options are:

  • user
  • user+password,
  • user+password+domain

I need user+subscriber+password. How can i pass this credentials?

code:

WebClient client = new WebClient();  
public void search()  
{  
        client.Credentials = new System.Net.NetworkCredential(username, subscriber, password); //not really exist  
        Byte[] pageData = client.DownloadData("https://example.com/");
...  
}

How i solved the problem: used a POST method with improvedWebClient class, that is like webclient but one that saves cookies. you can find it here .
code:

ImprovedWebClient wc = new ImprovedWebClient();
wc.DownloadData("https://theWebSite.com"); //to enter home page and get cookie
string URI = "https://theWebSite.com/authenticate"; //the login page
string myParameters = "user=theUserName&subscriber_number=1234-5678&password=myPassword&commit=LogIn"; //the parameters for the website
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.UploadString(URI, myParameters);

thanks for the help guys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM