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

Re^7: json return value

by poj (Abbot)
on Jul 16, 2013 at 07:27 UTC ( [id://1044522]=note: print w/replies, xml ) Need Help??


in reply to Re^6: json return value
in thread json return value

If you provide some default values for the postdata, your script should work when accessed through the browser . For example ;
#!/usr/bin/env perl use strict; use warnings; use CGI (); use JSON (); my $q = CGI->new; my $data = $q->param('POSTDATA') || '{"a":100,"b":300}'; my $json = JSON->new->utf8; my $input = $json->decode( $data ); my $a = $input->{a}; my $b = $input->{b}; my $c = $a + $b; print $q->header("application/json"); print $json->encode({ c => $c });
poj

Replies are listed 'Best First'.
Re^8: json return value
by stenasc (Novice) on Jul 16, 2013 at 07:50 UTC

    I wish !! Big fat error...

    Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@myurl.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

    Very tired and pissed off with this issue at this stage. Must be something fundamental wrong with the server.

      Again, see Re^7: json return value. The web server error log likely contains more information.

      The error message even says so.

      Ok, take a step back, try this simple script
      #!/usr/bin/env perl use strict; use warnings; use CGI; use CGI::Carp('fatalsToBrowser'); use JSON; my $q = CGI->new; print $q->header(), $q->start_html(-title=>"Hello World"), $q->h2("Hello World"), $q->end_html();
      I noticed on first line of your cgi that worked you had #!/usr/bin/perl. If this script doesn't work try changing that.
      poj

        Same thing when accessed through browser

        Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@tyder.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

        Server log is...

        16/Jul/2013:13:14:25 +0100 "GET /cgi-bin/test2.cgi HTTP/1.1" 404 - "-" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"

        That worked, but need a slight change...

        #!/usr/bin/env perl use strict; use warnings; use CGI; use CGI::Carp('fatalsToBrowser'); use JSON::PP(); my $q = CGI->new; print $q->header(), $q->start_html(-title=>"Hello World"), $q->h2("Hello World"), $q->end_html();

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-03-19 06:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found