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});
相关推荐
fengkai454519 分钟前
七、华为云网络类 + 计算类云服务实验总结
开发语言·php
神明不懂浪漫22 分钟前
【第四章】索引——B+树、回表,加快数据库的查找能力的利器
开发语言·数据结构·数据库·经验分享·笔记·b树
博、、23 分钟前
全民健身解决方案系统源码实战指南:从架构设计到部署全流程解析
开发语言·需求分析
liuze40826 分钟前
安装boss-zhipin-mcp(招聘)
开发语言·python
博、、36 分钟前
智慧场馆解决方案系统开发实战:从架构设计到落地指南
开发语言·需求分析
二十雨辰1 小时前
[Java]-场景题
java·开发语言
geovindu1 小时前
java:Observer Pattern
java·开发语言·后端·观察者模式·设计模式·行为模式
Am-Chestnuts1 小时前
通义千问任务清单怎么导出Word?用DS随心转保留层级和勾选项
开发语言·c#·word
承渊政道1 小时前
星空组网真实体验:Mac远程访问Ubuntu,SSH与HTTP全流程验证
ubuntu·http·macos·ssh·服务器管理·星空组网
liliangcsdn1 小时前
基于信号强度的稀疏选股算法的探索分析
开发语言·python