Can't login to wordpress using HttpWebRequest

dynander

Regular Member
Joined
Nov 16, 2008
Messages
279
Reaction score
55
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
 
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"
 
Try using a sniffer like wireshark to see if your app is sending the same stuff as a legitimate request.
 
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
 
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
 
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.
 
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
 
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
 
One of the best is http://www.microsoft.com/downloads/details.aspx?FamilyID=983b941d-06cb-4658-b7f6-3088333d062f&displaylang=en
Better than Wireshark which truncates bigger headers and easier to use as well.
 
Back
Top