camlet has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perlmonks, i have a simple http client that sends a few parameters to an http server. for port 80 it works fine.the server is on 8081 and when changing the port on client it doesnt pass the GET parameters. Am i putting the port in the wrong place?

use LWP;

$ua = LWP::UserAgent->new;

$ua->agent("camlet/ 0.1");

# Create a request

my $req = HTTP::Request->new(GET => 'http://server1:8081');

$req->content_type('application/x-www-form-urlencoded');
$req->content('request=event&source=camlet_cli&status=open&collection=camlet&time=12:00&severity=1&authorizationid= =test&description=test&datacenter=cam&ip=192.168.0.4&camlettype=camagent&type=GET');
my $res = $ua->request($req);


Wed Jun 04 23:07:01 EDT 2008 INFO {content-type=application/x-www-form-urlencoded, connection=TE, close, type=GET, host=75.101.157.65:4320, content-length=224, user-agent=camlet/0.1, te=deflate,gzip;q=0.3}

Replies are listed 'Best First'.
Re: LWP Http Port
by Gangabass (Vicar) on Jun 05, 2008 at 03:49 UTC

    You create GET request but try to send POST...

    For GET you must simply add your data into URI:

    my $req = HTTP::Request->new(GET => 'http://server1:8081/somescript?re +quest=event&source=camlet_cli&status=open&collection=camlet'); my $res = $ua->request($req);
Re: LWP Http Port
by kabeldag (Hermit) on Jun 06, 2008 at 12:16 UTC
    Actually, all those parameters are still being passed along, you are just not attaching them to the uri. Passing parameters to $req->content() is adding the parameters to the content portion of the HTTP packet... The port number makes no difference. Hmmm...

    This is how I would do it (in case anybody was wondering):
    use strict; use LWP::UserAgent; use LWP::Debug qw(+); use HTTP::Request; my $ua = LWP::UserAgent->new; $ua->agent("Wobbygong Shark/ 0.1"); # Create a request my $req_method = 'GET'; my $url = "http://thebigwobbygongsharkonheat.aquaworld.tv:8081/"; my $res; my $content_params = 'oneandthesame=;'; my $req = HTTP::Request->new( $req_method=>$url, HTTP::Headers->new( 'Content-Type'=>'application/x-www-form-urlencoded') ); $req->content($content_params); $ua->request($req);