The comment with passing them as the query string only works for GET parameters. This works for POST. As you can see I use the form entries username, password and login (the button) but in your case it might be entirely different values. So use a tool like Fiddler to catch which values a normal login is sending. When I did something similar I had to use a cookie-aware webclient because the service used cookies for session values. The service you are trying to access could use a query-session string - it entirely depends on the service.
Another problem I ran into when doing this, was that I had to fetch a session id from the html page and sent it for logging it. I have not included the code for that here, but I have it if you need it :)
var client = new CookieAwareWebClient();
client.Encoding = Encoding.UTF8;
// Post values
var values = new NameValueCollection();
values.Add("username", someusername);
values.Add("password", somepassword);
values.Add("login", "Login"); //The button
// Logging in
client.UploadValues(loginPageUrl, values); // You may verify the result. It works with https :)
// Download some secret page
var html= client.DownloadString(someurl);
CookieAwareWebClient
public class CookieAwareWebClient : WebClient
{
private CookieContainer cookieContainer = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
(request as HttpWebRequest).CookieContainer = cookieContainer;
}
return request;
}
}