Modus Ponens
Modus Ponens

Reputation: 54

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:

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/");
...  
}

Upvotes: 1

Views: 380

Answers (1)

Modus Ponens
Modus Ponens

Reputation: 54

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.

Upvotes: 1

Related Questions