Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi bliako,

Update

Please ignore the original version of this node. It is left there for completeness. In my haste I missed the part about adding: {'Content-type' => 'application/x-www-form-urlencoded'} to my REST call. I did and now things have moved along. Now I get all JSON results back, and the attempt to edit gives this error:
'error' => { 'code' => 'badtoken', '*' => 'See http://somehost.got.internal.net/mediawiki/api.php f +or API usage', 'info' => 'Invalid token' }
I'm sure I can work that out in a couple of minutes.

Thanks a million for you time.
R.
Original Node
thanks for taking your time on this. I see what you mean about the docco saying to put the query in the POST body and it makes sense. Something I am doing is still wrong though. I have added a print to show what the is being sent, and I have the URI and body split. Here is the post sub as is now

sub post { my $query = shift @_; print Dumper $client; $client->POST($api, $query); print "\$client->POST($api, $query)\n"; if ( $client->responseCode() == 200 ) { print "Got Data OK, decoding ... " if $debug; print Dumper $client->responseContent() ; my $data = $JSON->decode( $client->responseContent() ); print Dumper $data; return $data; } else { print "Failed with code $client->responseCode()\n"; print Dumper $client->responseContent(); } }
And here is the output, skip past the dump of the client to see that I am invoking:

$client->POST(/mediawiki/api.php, action=login&lgname=Marvin&lgpassword=diode&format=json)
random@gotsvl1140:~> ./LookupsToWiki.pl $VAR1 = bless( { '_config' => { 'host' => 'http://somehost.got.internal.net', 'useragent' => bless( { 'proxy' => {}, 'timeout' => 180, 'ssl_opts' => { 'verify_hostname' => 1 }, 'handlers' => { 'response_header' => bless( [ { 'owner' => 'LWP::UserAgent::parse_he +ad', 'callback' => sub { "DUMMY" }, 'm_media_type' => 'html', 'line' => '/usr/lib/perl5/vendor_per +l/5.18.2/LWP/UserAgent.pm:683' } ], 'HTTP::Config' ) }, 'protocols_forbidden' => undef, 'max_redirect' => 7, 'use_eval' => 1, 'max_size' => undef, 'show_progress' => undef, 'local_address' => undef, 'def_headers' => bless( { 'user-agent' => 'REST::Client/273' }, 'HTTP::Headers' ), 'no_proxy' => [], 'protocols_allowed' => undef, 'requests_redirectable' => [ 'GET', 'HEAD' ] }, 'LWP::UserAgent' ) } }, 'REST::Client' ); $client->POST(/mediawiki/api.php, action=login&lgname=Marvin&lgpasswor +d=volvo123&format=json) $VAR1 = '<!DOCTYPE html> <html lang="en" dir="ltr" class="client-nojs"> <head> <meta charset="UTF-8"/> <title>MediaWiki API help - Monitoring Services</title> <script>document.documentElement.className = document.documentElement. +className.replace( /(^|\\s)client-nojs(\\s|$)/, "$1client-js$2" );</s +cript> ","wgRelevantArticleId":0,"wgRequestId":"WwLj2gr-QFMAAE7vrZwAAAAF","wg +IsProbablyEditable":false,"wgVisualEditor":... Plenty more html here +...
there is a Sandbox here: https://www.mediawiki.org/wiki/Special:ApiSandbox Medi Wiki Sandbox but as its a web interface, I am not sure if you can hit it with Perl. I got some kids to feed now. I will log back in in a couple of hours and see if I can progress.

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to Re^4: Rest::Client Headers not getting through by Random_Walk
in thread Rest::Client Headers not getting through by Random_Walk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found