Massyn has asked for the wisdom of the Perl Monks concerning the following question:
#!/fellow/monks.pl I found the following code on http://timjoh.com/perl-post-automatically-to-wordpress-blog-with-wp-posterpl/ which will allow a user to publish information into a Wordpress blog. From what I can tell, the code is fine. The problem is when the the authentication bit starts, Wordpress issues a cookie, or at least tries to.
The problem is Wordpress comes back saying the browser doesn't support cookies.
Correct me if I'm wrong, but $ua->cookie_jar( {} ); is the cookie jar, right? Why doesn't LWP tell Wordpress the right thing? Is it something else?
use strict; use LWP::UserAgent; # ====== Parameters to change =============== my $burl = 'http://www.example.com/'; # don't forget the trailing slas +h my ( $usr, $pwd, $uid ) = ( 'admin', 'secret', 1 ); # uid=1 if you are + the initial administrator my $title = "Wordpress Post title"; my $body = "Wordpress body text"; # =========================================== # ua my $ua = LWP::UserAgent->new; #$ua->agent('wp-poster'); $ua->cookie_jar({}); # login print "Login : "; my $req = HTTP::Request->new( POST => $burl . 'wp-login.php' ); $req->content_type('application/x-www-form-urlencoded'); $req->content( sprintf('log=%s&pwd=%s&wp-submit=1&redirect_to=wp-admin +/post-new.php',$usr,$pwd) ); my $res = $ua->request( $req ); if ( $res->is_success ) { print "SUCCESS!!\n"; print $res->content; ##### Yes, we're successfull, but Wordpress says cookies aren' +t enabled... Huh ?? } else { print "FAILURE!!\n"; &debug($res, 0); exit(1); }
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LWP ignoring cookies??
by TOD (Friar) on Jan 05, 2008 at 05:17 UTC | |
by Massyn (Hermit) on Jan 05, 2008 at 06:02 UTC | |
by Massyn (Hermit) on Jan 05, 2008 at 07:56 UTC | |
by alexm (Chaplain) on Jan 05, 2008 at 18:17 UTC | |
by Anonymous Monk on Jan 05, 2008 at 11:27 UTC | |
by Massyn (Hermit) on Jan 06, 2008 at 09:17 UTC |