perl send HTTP Request

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});
相关推荐
2601_949146534 分钟前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
曹牧10 分钟前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
KYGALYX16 分钟前
服务异步通信
开发语言·后端·微服务·ruby
zmzb010323 分钟前
C++课后习题训练记录Day98
开发语言·c++
猫头虎1 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
YUJIANYUE2 小时前
PHP纹路验证码
开发语言·php
仟濹2 小时前
【Java基础】多态 | 打卡day2
java·开发语言
孞㐑¥2 小时前
算法——BFS
开发语言·c++·经验分享·笔记·算法
Re.不晚2 小时前
JAVA进阶之路——无奖问答挑战2
java·开发语言
八零后琐话2 小时前
干货:程序员必备性能分析工具——Arthas火焰图
开发语言·python