5 Replies - 2468 Views - Last Post: 11 June 2012 - 02:26 AM Rate Topic: -----

#1 solid-snake-coder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-June 12

I can't login to facebook with httpwebrequest

Posted 09 June 2012 - 11:49 AM

my codes here:

  string postdataman = "lsd=AVpgvQM_&email=myemail@wow.com&pass=12345678&persistent=1&default_persistent=1" + "&charset_test=€,´,€,´,水,",Є" + "&timezone=-180&lgnrnd=104940_e5yZ&lgnjs=1339181436&locale=en_US";
            string url = "http://facebook.com";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            byte[] bytearray = Encoding.UTF8.GetBytes(postdataman);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = bytearray.Length;
            Stream stream = req.GetRequestStream();
            stream.Write(bytearray, 0, bytearray.Length);
            WebResponse res = req.GetResponse();
            stream = res.GetResponseStream();
            StreamReader sr = new StreamReader(stream);
            string result = sr.ReadToEnd();
            textBox3.Text = result;
            if (result.Contains("blabla"))
            {
                MessageBox.Show("login successful);
            }
            stream.Close();
            res.Close();
            sr.Close();


why this code doesnt work :( it cant login to facebook. I am working on this for 24 hours... My eyes are hurting a lot now but still I cant solve this problem

Where is my error in my codes :( :(

*** Edit ***
Posted Image
Please keep the street language off the forums!

Is This A Good Question/Topic? 0
  • +

Replies To: I can't login to facebook with httpwebrequest

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,257
  • Joined: 27-December 08

Re: I can't login to facebook with httpwebrequest

Posted 09 June 2012 - 11:57 AM

Look at the existing APIs Facebook has, as they are better suited than developing your own.
Was This Post Helpful? 0
  • +
  • -

#3 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 182
  • View blog
  • Posts: 783
  • Joined: 27-October 11

Re: I can't login to facebook with httpwebrequest

Posted 09 June 2012 - 12:00 PM

Use code tags when posting code: [code] [ /code] ;)

Please describe your problem. We need more than just 'it doesn't work'. Does it have a compile time or run time error or does it just not work as you intended.

Use using statements for your streams, that way you don't have to worry if they are flushed and closed since it's done for you.

Take a look at a tutorial about logging in to websites programatically: C# - Log In To Website Programmatically

Although I can't find any obvious mistake in your code, one possibility is that your post data isn't in the correct format or contains invalid information.

EDIT: Now that macosxnerd101 has mentioned FB API's, I've remembered that FB also has a C# SDK that you can use. Take a look at a tutorial on how to use it: Using Facebook SDK 3.01 with C#.NET

The Facebook C# SDK.

Some more tutorials:
Facebook C# SDK - Writing your first Facebook Application
Automating Facebook Login using WebBrowser Control in C#

You should always search the web before you post a question in a forum. Take a look at here: Getting What You Need By Doing A Decent Search Of The Internet for more information on searching the internet.
Was This Post Helpful? 0
  • +
  • -

#4 solid-snake-coder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-June 12

Re: I can't login to facebook with httpwebrequest

Posted 10 June 2012 - 12:29 PM

I dont want to use any API... MY Purpose is learning about HTTPWEBREQUEST!

Can anybody give a httpwebrequest bot examples to me??
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,463
  • Joined: 05-May 12

Re: I can't login to facebook with httpwebrequest

Posted 10 June 2012 - 04:47 PM

If you want to learn about HttpWebRequest, start simple. Start with a WebRequest that just gets a web page by starting off with the GET verb. Once you've learned what you needed to with GET, set up a simple web server that responds to a POST verb and learn what you need to learn from that.

Once you've got those pieces down pat, start looking at interfacing with FaceBook.
Was This Post Helpful? 1
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6106
  • View blog
  • Posts: 23,653
  • Joined: 23-August 08

Re: I can't login to facebook with httpwebrequest

Posted 11 June 2012 - 02:26 AM

And make sure you understand how the HTTP protocol works by reading the RFC.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1