http://qs321.pair.com?node_id=1214991


in reply to Re^3: Rest::Client Headers not getting through
in thread Rest::Client Headers not getting through

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!