Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Getting error while decoding JSON object via POST method

by perlCrazy (Monk)
on Feb 06, 2013 at 10:26 UTC ( #1017378=note: print w/ replies, xml ) Need Help??


in reply to Re: Getting error while decoding JSON object via POST method
in thread Getting error while decoding JSON object via POST method

thanks for response, still getting same error. i tried code : cleint :

use strict; use warnings; use JSON (); use LWP::UserAgent (); use HTTP::Request::Common qw( POST ); use Data::Dumper; my $data = { a => 40, b => 2 }; my $json = JSON->new->utf8->allow_nonref; my $ua = LWP::UserAgent->new; my $req = POST( "$my_url", Content_Type => 'application/json', Content => $json->encode($data), ); my $response = $ua->request($req); if ($response->is_success) { #print Dumper($response->content()); my $perlData = $json->decode($response->content()); print Dumper($perlData); } else{ print " inside falied block\n"; }
server side:
#use cgi.pm to get json as input my $q = CGI->new; my $json = JSON->new->utf8; my $input = $json->decode( $q->param('POSTDATA') ); #my $input = $q->param('POSTDATA'); my $a = $input->{'a'}; my $b = $input->{'b'}; my $c = $a + $b; print $q->header("application/json"); #print Dumper($input); print $json->encode({ c => $c });
output of run : ./test_client.pl $VAR1 = { 'error_msg' => 'Failed during execution: malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") ', 'status_code' => 500 }; Thanks


Comment on Re^2: Getting error while decoding JSON object via POST method
Select or Download Code
Re^3: Getting error while decoding JSON object via POST method
by Anonymous Monk on Feb 06, 2013 at 10:35 UTC
    And the reason you don't DUMP the data is because?
      which data ?
      just dumped the data server side and loos like :
      {"a":40,"b":2={"a":40,&#034
      it is broken.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2014-07-10 14:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (212 votes), past polls