Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re^2: Building a URL Query String from a Data Structure by dorko
in thread Building a URL Query String from a Data Structure by dorko

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 scrutinizing the Monastery: (3)
As of 2024-03-30 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found