Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: json return value

by Anonymous Monk
on Jul 11, 2013 at 08:43 UTC ( [id://1043658]=note: print w/replies, xml ) Need Help??


in reply to json return value

Do I need to install anything on the webserver to handle json or is it handled by default?

What does that mean? Its all just bytes / http, so what further handling are you talking about?

Try

#!/usr/bin/env perl -- use strict; use warnings; use JSON (); use WWW::Mechanize 1.72; Main( @ARGV ); exit( 0 ); sub Main { my $data = { a => 40, b => 2 }; my $json = JSON->new->utf8; my $ua = WWW::Mechanize->new; $ua->post( "http://myurl/public_html/cgi-bin/json-addition.cgi", Content_Type => 'application/json', Content => $json->encode($data), ); $ua->res->dump; if( $ua->is_json ){ my $result = $json->decode( $ua->content ); print $result->{c}, "\n"; } } sub WWW::Mechanize::is_json { int( 'application/json' eq $_[0]->ct ) }

General notions you should be aware of as well as lists of things to check are found in Coping with Scoping , CGI to mod_perl Porting. mod_perl Coding guidelines , brian's Guide to Solving Any Perl Problem, CGI Help Guide , Troubleshooting Perl CGI scripts , On debugging, verify everything, talk to teddybear ...

Looks to me like /public_html/ is something extra you don't need

Replies are listed 'Best First'.
Re^2: json return value (sub WWW::Mechanize::is_mimetype )
by Anonymous Monk on Jul 11, 2013 at 08:57 UTC

    is_json is like is_html, one trick pony :)

    use MIME::Types; our $mimetypes = MIME::Types->new; sub WWW::Mechanize::is_mimetype { goto &WWW::Mechanize::is_mt } sub WWW::Mechanize::is_mt { $mimetypes->mimeTypeOf( $_[1] )->equals( $ +_[0]->ct ) }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-24 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found