perl send HTTP Request
使用Perl进行发送HttP请求
perl
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Headers;
use JSON::PP;
my $test_url = "htttp://127.0.0.1:8080/update/";
sub sendHttp{
my $user_agent = LWP::UserAgent->new(timeout=>60);
my ($url, $method, $header_ref, $data_ref) = @_;
my $request = HTTP::Request->new($method => $url, HTTP::Headers->new (%{$header_ref}), $data_json);
$request->header(Content_Type => 'application/json');
my $response = $ua->request($request);
return decode_json($response->content);
}
此时我们可以使用这个函数对http服务发送请求。
perl
my $json_response = sendHttp($test_url, "POST", {"ttt-cookie"=>"abcd"}, {param1 => "param1"});
print($json_response -> {status});
print($json_response -> {message});