Sinatra with Perl Client

16 views
Skip to first unread message

dominic prakash

unread,
Aug 2, 2017, 3:38:34 PM8/2/17
to sinatrarb

My Server

require 'sinatra'
set :port, 8080
get '/get' do
 
"GET Hello World"
end

post
'/post' do
 
"POST Hello World"
end


Ruby Client - Working

require "rest-client"
response
= RestClient.post 'http://localhost:8080/post', {param1: 'one'}
puts response


Curl Works
curl -v -X POST http://localhost:8080/post

If I call the URL through a browser it works as well.

My Perl client is not working for this server. I am aware this is kind of Perl question, but works on other servers.

use REST::Client;
my $client = REST::Client->new();
$client
->GET('http://localhost:8080/get');
print $client->responseContent();

or

use warnings;
use LWP::UserAgent;
use HTTP::Request;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new( GET => 'http://localhost:8080/get');
my $response = $ua->request($req);
print $response->code . "\n";



Appreciate any pointers.

Сергей Жуматий

unread,
Aug 3, 2017, 4:23:23 AM8/3/17
to sinatrarb
  Do you have trouble with GET only? Is POST wirking with perl client?

среда, 2 августа 2017 г., 22:38:34 UTC+3 пользователь dominic prakash написал:

Keith Bennett

unread,
Aug 3, 2017, 5:21:13 AM8/3/17
to sina...@googlegroups.com
Can you be more specific about the error that occurs when you try using the Perl client? Do you get no output at all? An error message? I tried it and it worked:

➜  perl-test   cat x.pl

use REST::Client;
my $client = REST::Client->new();
$client->GET('http://localhost:8080/get');
print $client->responseContent();
➜  perl-test   perl x.pl
GET Hello World%



--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinatrarb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages