Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Building a URL Query String from a Data Structure

by dorko (Prior)
on Feb 10, 2016 at 13:07 UTC ( #1154851=note: print w/replies, xml ) Need Help??


in reply to Re: Building a URL Query String from a Data Structure
in thread Building a URL Query String from a Data Structure

Thank you taking the time to help out a poor lost soul.

I got it installed and working just before I left work yesterday. (CPAN got stuck in a seemingly infinite loop working out dependencies, so I just started installing the dependencies until CPAN could get HTTP::Request::JSON installed.)

This code:

#!/usr/bin/perl use strict; use warnings; use feature("say"); use Data::Dumper::Simple; use HTTP::Request::JSON; my $perl_structure = { 'sub' => { 'name' => 'foo', 'message' => 'bar' }, 'name' => 'test name', 'file_ids' => [ 1, 2 ] }; my $request = HTTP::Request::JSON->new; $request->json_content($perl_structure); say $request->decoded_content; say Dumper $request;

results in this output:

{"file_ids":[1,2],"name":"test name","sub":{"message":"bar","name":"fo +o"}} $request = bless( { '_content' => '{"file_ids":[1,2],"name":"test name +","sub":{"message":"bar","name":"foo"}}', '_uri' => undef, '_headers' => bless( { 'content-type' => 'applicat +ion/json', 'accept' => 'application/js +on' }, 'HTTP::Headers' ), '_method' => undef }, 'HTTP::Request::JSON' );

So it looks like HTTP::Request::JSON creates an HTTP::Request object set up for a POST that contains a JSON payload.

That gets me two thirds the way there, but I'm missing the CGI query string. I'm working with a RESTful web API. I need to send a GET and the API only accepts the query string. It ignores any content body that is sent. Actually, that's why I'm doing this. The API used to work fine with JSON sent as an attachment, then somebody got all standards compliant (or something) and now their GET requests only work with query strings passing data.

Cheers,

Brent

-- Yeah, I'm a Delt.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1154851]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2020-05-30 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (171 votes). Check out past polls.

    Notices?