.

logging into a website the c# way (cookies)

var cookies = new CookieContainer();
ServicePointManager.Expect100Continue = false;

var request = (HttpWebRequest)WebRequest.Create("http://www.hotfile.com/login.php");
request.CookieContainer = cookies;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (var requestStream = request.GetRequestStream())
using (var writer = new StreamWriter(requestStream))
{
    writer.Write("user=XX&pass=XX&returnto=/");
}

using (var responseStream = request.GetResponse().GetResponseStream())
using (var reader = new StreamReader(responseStream))
{
    var result = reader.ReadToEnd();
    Console.WriteLine(result);
}

2 Responses to this post.

  1. Posted by David on 12.05.12 at 4:46 pm

    Could you provide a little more detail as far as the username and password. Specifically, how the writer.Write string should be formatted with respect to logging in to different websites? Say, Twitter, for example? What would that string look like?

  2. Posted by pietman on 12.05.12 at 4:46 pm

    It is unique for each and every website, so my recommendation would be to use Fiddler: http://www.telerik.com/download/fiddler
    and look at what data is submitted.
    You’ll find it under: Inspectors -> Raw
    simply copy & paste that string

What's your thoughts on this?

*

Protected by WP Anti Spam