1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can't login to wordpress using HttpWebRequest

Discussion in 'C, C++, C#' started by dynander, Apr 21, 2009.

  1. dynander

    dynander Regular Member

    Joined:
    Nov 16, 2008
    Messages:
    279
    Likes Received:
    53
    Could anyone login to wordpress.com using HttpWebRequest?

    In firefox, the login POST return 4 cookies and a "Location" header to redirect to wp-admin/, but in my code it only return 2 cookies and no header redirection.


    I'm trying to do a little bot that log into wordpress blogs in wordpress.com. The objective is to allow to post and edit blogroll, among other things
     
  2. BozoClown

    BozoClown Junior Member

    Joined:
    Jan 4, 2009
    Messages:
    150
    Likes Received:
    106
    What language are you using?
     
  3. dynander

    dynander Regular Member

    Joined:
    Nov 16, 2008
    Messages:
    279
    Likes Received:
    53
    I'm using C#

    I also use a HTTP Header addin to try to mimic all the headers sent by firefox

    They set a cookie when you first go to wp-login.php, and then there are a funny header: x-hack or x-hacker: "If you see this, go to our page and apply for a job"
     
  4. Anigma

    Anigma Newbie

    Joined:
    Apr 16, 2009
    Messages:
    5
    Likes Received:
    1
    Home Page:
    Try using a sniffer like wireshark to see if your app is sending the same stuff as a legitimate request.
     
    • Thanks Thanks x 1
  5. dynander

    dynander Regular Member

    Joined:
    Nov 16, 2008
    Messages:
    279
    Likes Received:
    53
    Thanks wireshark I was able to know better why this don't work:

    1) I create a get request to wp-login

    2) I invoke "GetResponse", and server return a response with a cookie

    3) I create a post request to wp-admin, with the cookie and the form fields

    4) when I write the post data, even before I ask for the response, server send a 302 with the cookies I want (4 cookies)

    5) I'm unable to get those cookies nor that response

    6) when I call method "GetResponse" in the Request created in 3), I see another 302, this one without the cookies



    I tried everything, I've changed the valules of almost all propierties of the request object, but nothing
     
  6. dynander

    dynander Regular Member

    Joined:
    Nov 16, 2008
    Messages:
    279
    Likes Received:
    53
    Well, I finally made it. Not sure how, almost 3 Am here and I'm falling sleep, but It works. When I finally understand why the hell I did, I'll share.

    PS: @Anigma: Very thanks for the sniffer tip
     
  7. Anigma

    Anigma Newbie

    Joined:
    Apr 16, 2009
    Messages:
    5
    Likes Received:
    1
    Home Page:
    No problem. Glad I could help.
     
  8. tehmadcracker

    tehmadcracker BANNED BANNED

    Joined:
    Apr 19, 2009
    Messages:
    155
    Likes Received:
    502
    i had problems with this in the past too, i ended up figuring it out as well, but ill be damned if i can remember or even find the code, however, if anyone in the future reads this post, chilkat has a component to do just this.
     
  9. Grishnakh

    Grishnakh Newbie

    Joined:
    Dec 24, 2009
    Messages:
    7
    Likes Received:
    0
    Define an user-agent. It's always better.

    You can use this one.
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9
     
  10. nemsis

    nemsis Jr. VIP Jr. VIP Premium Member

    Joined:
    Sep 27, 2009
    Messages:
    173
    Likes Received:
    283
    you can also use httpfox to get the exact headers sent by firefox. it also provides a nice gui showing post names and values, a raw post string etc. this is a must have extension for those who use httpwebrequest
     
  11. kaidoristm

    kaidoristm Power Member

    Joined:
    Feb 13, 2009
    Messages:
    561
    Likes Received:
    726
    Occupation:
    Freelancer
    Location:
    Estonia
    Home Page:
    I like Tamper Data for this work :)
     
  12. int80

    int80 Newbie

    Joined:
    Jan 13, 2010
    Messages:
    8
    Likes Received:
    9
    Yeah tamper data is good, or live http headers.
     
  13. kaidoristm

    kaidoristm Power Member

    Joined:
    Feb 13, 2009
    Messages:
    561
    Likes Received:
    726
    Occupation:
    Freelancer
    Location:
    Estonia
    Home Page:
    One of the best is Microsoft Network Monitor
    Better than Wireshark which truncates bigger headers and easier to use as well.
     
  14. divinci

    divinci Junior Member

    Joined:
    Sep 25, 2007
    Messages:
    111
    Likes Received:
    15
    nice find! I'm still amazed how many tools mr gates provides us hkrs in the persuit of google domination :)
    Posted via Mobile Device