Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: json return value

by stenasc (Novice)
on Jul 14, 2013 at 22:27 UTC ( #1044240=note: print w/ replies, xml ) Need Help??


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

Thank you very much. I greatly appreciate it. I get the correct value returned when I use the URL http://buzzword.org.uk/2013/json-addition.cgi but I get malformed JSON string, neither array, object, number, string or atom, at er offset 0 (before "<!DOCTYPE HTML PUBLI...") at json_client.pl line 12 when I use my own URL http://myurl.com/cgi-bin/json_mode.cgi. I have installed the server in the cgi-bin directory with permission 755 and the perl has valid syntax etc. It looks as if I cannot access the cgi file in the cgi-bin directory. Do you know a way around this?

I also see it described as text/cgi whereas some, but not all of the other cgi files are described as application/cgi. Any ideas why this is the case?


Comment on Re^4: json return value
Re^5: json return value
by Anonymous Monk on Jul 14, 2013 at 23:44 UTC
Re^5: json return value
by tobyink (Abbot) on Jul 15, 2013 at 05:45 UTC

    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

      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.

      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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-12-26 05:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (165 votes), past polls