Hi. Sorry if this type of thing has been asked before. I looked at a bunch of other topics here and on other sites but nothing has helped.
I'm trying to convert a PHP class into perl. It uses CURL to log into (with digest authentication) and post some parameters in order to collect trophy data from the playstation network. Original PHP code can be found here if you're curious: http://psnapi.org/?page=forum&forum=4&topic=69
My problem right off the bat is, I can't even get it to log in properly using perl. I just keep getting error 401. If I try to log in with a browser, it works (HTTP 200 OK) but then I get a 404 error because I haven't posted anything. Also, if I try to log into my own site (basic_auth), it DOES work.
I'd like to stick with using LWP and HTTP if at all possible. I know there are CURL and WWW::Mechanize modules for perl, but every version I've tried to install seems to be incompatible with my version of perl.
This is my code at the moment. I've also tried using basic_auth, get(), head() and post(), all with different parameters but everything just gives me error 401. Also, for the credentials method, I'm unsure which port the site uses. Could that be my whole problem and, if so, how can I find the necessary port?
#!C:/Perl/bin/perl.exe use LWP; $site[0] = "http://searchjid.usa.np.community.playstation.net/basic_vi +ew/func/search_jid"; $site[1] = "http://searchjid.eu.np.community.playstation.net/basic_vie +w/func/search_jid"; $site[2] = "http://searchjid.jpn.np.community.playstation.net/basic_vi +ew/func/search_jid"; $user = "c7y-basic01"; $pass = "A9QTbosh0W0D^{7467l-n_>2Y%JG^v>o"; for ($i=0; $i<@site; $i++) { $browser = LWP::UserAgent -> new; $browser -> agent("PS3Community-agent/1.0.0 libhttp/1.0.0"); $browser -> credentials("searchjid.usa.np.community.playstation.net/ +basic_view/func/search_jid:80","c7y-basic",$user=>$pass) . "\n\n"; print $browser -> head($site[i]) -> as_string . "\n\n"; # ------ alternate method ------ # $browser = LWP::UserAgent -> new; # $browser -> agent("PS3Community-agent/1.0.0 libhttp/1.0.0"); # $req = HTTP::Request -> new(GET => $site[$i]); # $req -> authorization_basic($user,$pass); # print $browser -> request($req) -> as_string . "\n\n"; # ------------------------------ }
---- And this is the output I always get ---
HTTP/1.1 401 Authorization Required Connection: close Date: Sat, 21 Apr 2012 03:54:44 GMT WWW-Authenticate: Digest realm="c7y-basic", nonce="XXXXXXX+BAA=XXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", algorithm=MD5, qop="auth" Content-Type: text/html; charset=iso-8859-1 Client-Date: Sat, 21 Apr 2012 03:54:47 GMT Client-Peer: 198.107.128.164:80 Client-Response-Num: 1
What am I doing wrong? (The XXXXX stuff is random every time).
In reply to How can I use LWP to log into digest-auth site and do post() (converting from PHP CURL) by fgsfds100
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |