Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^6: json return value

by stenasc (Novice)
on Jul 15, 2013 at 20:44 UTC ( #1044456=note: print w/ replies, xml ) Need Help??


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

Yes...it gives me this..

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.

However if I have a small cgi like the following, it works fine when accessed through the browser

#!/usr/bin/perl print "Content-type:text/html\r\n\r\n"; print '<html>'; print '<head>'; print '<title>Hello Word</title>'; print '</head>'; print '<body>'; print '<h2>Hello World</h2>'; print '</body>'; print '</html>';

I've been in contact with the server administrator and he sent me the log file results.

Mon Jul 15 14:49:20 2013 error client 87.194.165.154 Premature end of script headers: json_mode.cgi

He also suggested that I add the following to the code, but that is already in the code He also told me that it was because the script wasn't outputting valid html headers.

print("Content-type: text/json"); or print("Content-type:application/json");

The client is working fine because I can get the correct response from http://buzzword.org.uk/2013/json-addition.cgi'


Comment on Re^6: json return value
Download Code
Re^7: json return value
by poj (Priest) on Jul 16, 2013 at 07:27 UTC
    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

      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
Re^7: json return value
by Anonymous Monk on Jul 16, 2013 at 08:23 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-09-02 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls