#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    How to send data to server use httpwebrequest!


    I want login LiveJournal.com,but my response return null!Please help me!thanks very much!
    string url = string.Format("livejournal.com/login.bml");
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040707 Firefox/0.9.2";
    request.Method = "POST";
    request.Accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    request.KeepAlive = true;
    request.ContentType = @"application/x-www-form-urlencoded";
    request.Referer = string.Format("(livejournal.com/login.bml=1");
    request.CookieContainer = cookieContainer;

    // Send the log-in data
    string postData = string.Format("response=&user={0}&password={1}&expire=close&bindip=no&action%3Alogin=Log+in...", username, password);
    request.Method = "POST";
    byte[] postBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(postData);
    request.ContentLength = postBuffer.Length;
    System.Console.WriteLine(postBuffer);
    Stream postDataStream = request.GetRequestStream();
    postDataStream.Write(postBuffer, 0, postBuffer.Length);
    postDataStream.Close();

    // Get the response

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,055
    Rep Power
    9398
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0
    thanks,i want login,but why response return null???
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,055
    Rep Power
    9398
    Well yeah, you want to log in. But what for? Maybe there's an easier way to get it.

IMN logo majestic logo threadwatch logo seochat tools logo