Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

LWP Authorisation issue

by kapila (Acolyte)
on Feb 25, 2013 at 11:36 UTC ( #1020498=perlquestion: print w/ replies, xml ) Need Help??
kapila has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to integrate Bugzilla with ReviewBoard writing code in perl. I have tried to write a code. curl command which is working
curl -k -H "Authorization: Basic YWRtaW4=" -X POST -d "{\"repository_ +path\":":pserver:user:pwd@svn:/opt/cvsroot",\"username\":"admin",\"pa +ssword\":"admin",\"submit-as\":"admin"}" "http://codereview.xyz.com/a +pi/r/new/"
It is giving me full html page with js error
#!/usr/local/bin/perl use LWP::UserAgent; use MIME::Base64; $url="http://codereview.xyz.com/api/review-requests/"; $newurl="http://codereview.xyz.com/r/new/"; $user="admin"; $pwd="admin"; $text="$user:$pwd"; $text = encode_base64($text); #print "Encoded text: $text\n"; %param =( "repository_id" =>"cvsrepo", "repository_path" =>":pserver:user:pwd\@svn:/opt/cvsroot", "username" => "admin", "password" => "admin", "submit-as" => "username", ); my $ua = LWP::UserAgent->new; $ua->timeout(TIMEOUT); $ua->protocols_allowed(['http', 'https']); $ua->default_header('Basic' => $text); $ua->credentials($newurl,$user,$pwd); $resp = $ua->get($url); print($resp->status_line(), "\n"); print("Add handler:\n"); $ua->add_handler( response_header => sub { print "HANDLER\n"; +}, %param); print $ua->handlers('response_header', $resp)."\n"; push @{ $ua->requests_redirectable }, 'POST'; print $ua->show_progress."\n"; my $response = $ua->post($newurl,%param); if ($response->is_success) { print $response->decoded_content; } else { die $response->status_line; }
Error its not posting ..
<h1>JavaScript is turned off</h1> <p>Review Board requires JavaScript in order to function. Please turn it on in your browser preferences. <p>Firefox users: if you prefer to turn on JavaScript only for specific sites, we recommend the <a href="https://addons.mozilla.org/en-US/firefox/addon/722">NoSc +ript extension</a>.</p>

Comment on LWP Authorisation issue
Select or Download Code
Re: LWP Authorisation issue (not really)
by Anonymous Monk on Feb 25, 2013 at 11:49 UTC
    examine what the curl version sends, then send the same in perl, Web Testing with HTTP::Recorder can help you , as can livehttpheaders/wireshark, even curl debug option

      Thanks i will try to read this never heard of it.

      Plus,Do u seek any issue in my code?

        Plus,Do u seek any issue in my code?

        I see some issues, but I don't know if fixing them will help you

        I see you didn't use strict/warnings to cut your development time in half!

        I see you don't dump in handler but do something else

        I see you check the value of show_progres instead of turning it on

        You use the bareword TIMEOUT for timeout

        I see add your own Basic header and use/credentials -- I don't know what that will do, but that is kind of the purpose behind LWP, to do that for you

        Also, WWW::Mechanize can simplify your LWP::UserAgent interaction, no need for constant status_line checks as it will die for you,
        or saving the response, it keeps track of all that ( WWW::Mechanize::Cookbook, mech-dump )

        WWW::Scripter is a Mechanize helper

Re: LWP Authorisation issue
by daxim (Chaplain) on Feb 26, 2013 at 08:58 UTC
    Install Wireshark instead, it'll go quicker than learning how to use HTTP::Recorder. Record the working curl request/response.

    Select Analyze → Display filters…, select HTTP and press OK. Select the curl request in the main window. Select Analyze → Follow TCP Stream. The dialog shows now the request/response pair in text form. Copy and paste this text here to Perlmonks.

      Install Wireshark instead ...

      I don't like this advice, it shifts the burden of recreating HTTP::Request objects onto humans, when HTTP::Recorder can do it for you

      IMHO this is not reasonable, we're monks, not monkeys

        And I don't like your advice (assuming you are the same anonymonk as in Re: LWP Authorisation issue (not really)). With Wireshark, this matter would already be resolved within minutes, and instead kapila gets send into a dead end that costs him already a day.

        When you volunteer to help people here, then optimise your processes for them, not yourself. Else, why bother? Half-arsedness does more harm than not helping at all.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1020498]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2014-07-23 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (131 votes), past polls