Depending on the site the NetworkCredential wont be used. Take a look at the actual Log In form for a few things:
- What is the action of the Log In form?
- What is the name of the User Name field?
- What is the name of the Password field?
Then with that information you can make sure you POST to the right URL, some sites post log in requests to another page. Then you can add your User Name and Password to the content of the Request.
something like this:
Assuming UserName is the name of the ID textbox and Password is the name of the Password textbox.
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("url");
request.Method = "POST";
request.UseDefaultCredentials = false;
request.PreAuthenticate = true;
request.Credentials = new NetworkCredential("id", "pwd", "domain");
string formData = "UserName=" + id + "&Password=" + pwd;
using (var writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(formData);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
this.Response.Write(response.StatusCode);
This code was written directly into the browser so it probably wont compile.