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});
相关推荐
c++之路1 天前
CMake 系列教程(二):基础命令详解
开发语言·c++
南境十里·墨染春水1 天前
C++ 工厂模式:从入门到进阶,彻底掌握对象创建的艺术
开发语言·c++·算法
JosieBook1 天前
【数据库】时序预测能力的分级进化:TimechoAI如何让每一类用户都能精准预见未来
java·开发语言·数据库
加号31 天前
【C#】 文件与目录管理:创建、删除操作的技术解析
开发语言·c#
diving deep1 天前
脚本速览-python
开发语言·python
一生了无挂1 天前
Java处理JSON技巧教学(从基础到高阶实战全覆盖)
java·开发语言·json
swordbob1 天前
Spring 单例 Bean 是线程安全的吗?
java·开发语言
小小编程路1 天前
C++ 异常 完整讲解
开发语言·c++
AI科技星1 天前
数术工坊 · 第四卷 橡皮泥江湖(拓扑学)【完整定稿】
c语言·开发语言·汇编·electron·概率论·拓扑学
张忠琳1 天前
【Go 1.26.4】Golang Select 深度解析
开发语言·后端·golang