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

Have you visited http://myurl.com/cgi-bin/json_mode.cgi in your browser?

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

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

    Yes...I get the following. It looks as if I don't have permission to contact the website.

    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.

      Have you looked into the web server error log? Usually, it contains the detailed error information.

Re^6: json return value
by stenasc (Novice) on Jul 15, 2013 at 20:44 UTC

    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'

      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.