I am having an issue with Json RPC and mod_perl. I am trying to return a value from a cgi script which is running in Apache through mod_perl. But in the return value, following apache headers are automatically added and therefore I am not able to access the return value from my client script.
Status: 200 Content-Type: application/json; charset=UTF-8
In my Apache configuration file I have following directives.
LoadModule perl_module modules/mod_perl.so PerlSwitches -w PerlSwitches -T Alias /perl /var/www/html/perl <Directory /var/www/html/perl> SetHandler perl-script PerlResponseHandler ModPerl::Registry Options +ExecCGI </Directory>
My cgi script is pasted below.
#!/usr/bin/perl use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use JSON::RPC::Server::CGI; use strict; use Data::Dumper; my $server = JSON::RPC::Server::CGI->new; $server->dispatch('Myapp')->handle(); The Myapp.pm is #!/usr/bin/perl package Myapp; use base qw(JSON::RPC::Procedure); # Perl 5.6 or more than use strict; use Data::Dumper; sub test : Public(u1:str){ my ($s, $obj) = @_; my $u1 = $obj->{u1}; return $u1; } 1;
My client side script is
#!/usr/bin/perl use JSON::RPC::Client; use Data::Dumper; my $client = new JSON::RPC::Client; my $uri = 'http://IP/perl/test.cgi'; $client->prepare($uri, ['test']); $str= $client->test('testing'); print "$str\n\n";
In normal case the output should be testing . But in my case I am getting the below error.
malformed JSON string, neither array, object, number, string or atom, +at character offset 0 (before "Status: 200\r\nConte...") at /usr/loca +l/share/perl5/JSON/RPC/Client.pm line 186
The issue is because some http headers are automatically get added to the return value. Is there any way to suppress these headers? Note: Kindly don't recommend normal cgi scripts or running perl script as daemon because it is already working and tested from my end. We are using mod_perl for high performance.

In reply to Issue in Json RPC with mod_perl by nijin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.