Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:10:40+00:00 2026-05-27T22:10:40+00:00

I have been given requirements to not use the JSON::RPC::Client, instead use LWP to

  • 0

I have been given requirements to not use the JSON::RPC::Client, instead use LWP to do the calls.

Here is my code:

Server:

#!/usr/bin/perl

use strict;
use lib ".";

use ServerLib;

use JSON::RPC::Server::Daemon;

die "Do Not run as Root\n" if($< == 0);
print "Starting Daemon\n";
my $daemon =  JSON::RPC::Server::Daemon->new(LocalPort => 8000);
$daemon->dispatch({'/jsonrpc/API' => 'ServerLib'})->handle();
exit;

Module:

package ServerLib;

use base qw(JSON::RPC::Procedure); # Perl 5.6 or more than
use JSON;
use Data::Dumper;
use Sys::Hostname;
use Net::RabbitMQ;
use YAML qw( LoadFile );
use strict;

$| = 1;
my $VERSION = 0.2.0;

sub echo : Public(message:string) {
    my ($s, $obj) = @_;
    my $message = $obj->{'message'};
    print "got message => $message\n";
    print "returning: $message\n";
    my $object = { message => $message,
                   foobar => "garbage" };

    return $object;
 }
package ServerLib::system;

sub describe {
    {
        sdversion => "0.1",
        name      => 'ServerLib',
    };
}

1;

Working Client:

#!/usr/bin/perl

use strict;

use JSON::RPC::Client;
use Data::Dumper;
my $client = new JSON::RPC::Client;

my $uri = 'http://localhost:8000/jsonrpc/API';
my $obj = {
    method  => 'echo', # or 'MyApp.sum'
    params  => ["my message"],
};

my $res = $client->call( $uri, $obj );

if($res){
   if ($res->is_error) {
       print "Error : ", $res->error_message;
   }
    else {
       print Dumper($res->result);
   }
 }
 else {
    print $client->status_line;
 }

Non Working client:

#!/usr/bin/perl -w

use strict;
use JSON;
use LWP::Simple;
use Data::Dumper;

my $actionurl = "http://localhost:8000/jsonrpc/API";

my $ua = LWP::UserAgent->new();
$ua->agent("JSONClient/0.1");

my $object = { method => "echo",
           params => [@ARGV ] };

my $json = to_json($object);
print "$json\n";
my $req = HTTP::Request->new(POST => $actionurl);
$req->content_type('application/json');
$req->content($json);

my $res = $ua->request($req);
if ($res->is_success)
{
    print "Succeeded:\n" . Dumper($res->dump);
    print "DUmp: ". $res->dump;
    my $result = to_json($res->content);
 }
  else
      {
        print "Failed\n";
 }

I see the server process for both clients but the second client has no data returned to it.

DUmp: HTTP/1.1 200 OK
Connection: close
Date: Tue, 03 Jan 2012 18:24:24 GMT
Server: libwww-perl-daemon/5.827
Content-Type: application/json; charset=UTF-8
Client-Date: Tue, 03 Jan 2012 18:24:24 GMT
Client-Peer: 127.0.0.1:8000
Client-Response-Num: 1

(no content)

Does anybody see what I am missing? It should be pretty simple but for some reason I can’t find the response string like the RPC::Client sees.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:10:41+00:00Added an answer on May 27, 2026 at 10:10 pm

    This was a tricky one. One of my co-workers found it and he isn’t on Stackoverflow so I will post the fix.

    This:

    my $object = { method => "echo",
           params => [@ARGV ] };
    

    Needed version => “1.1”, added to it to become:

    my $object = { method => "echo",
                   params => [@ARGV],
                   version => "1.1",};
    

    Not sure why this matters, but once it was added it worked like a charm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given the task of internationalizing a large client-server application. The remit
I have been given a requirement where I need to support multiple databases in
I have been given two different Microsoft Word document that my virus scanner has
I have been given a DLL (InfoLookup.dll) that internally allocates structures and returns pointers
I have been given a specification that requires the ISO 8601 date format, does
I have been given the following request. Please give 7% of the current contacts
I have been given the option to either have a Windows laptop or a
I have been given the task of adding functionality to an existing IIS 6.0
I have been given the unenviable task of cleaning up after a developer who
I have been given an app written by someone else and the error I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.