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});
相关推荐
2501_915921439 分钟前
iOS IPA 混淆实测分析:从逆向视角验证加固效果与防护流程
websocket·网络协议·tcp/ip·http·网络安全·https·udp
2501_915918419 分钟前
打造可观测的 iOS CICD 流程:调试、追踪与质量保障全记录
websocket·网络协议·tcp/ip·http·网络安全·https·udp
黄雪超24 分钟前
JVM——函数式语法糖:如何使用Function、Stream来编写函数式程序?
java·开发语言·jvm
ThetaarSofVenice31 分钟前
对象的finalization机制Test
java·开发语言·jvm
思则变43 分钟前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
lijingguang1 小时前
在C#中根据URL下载文件并保存到本地,可以使用以下方法(推荐使用现代异步方式)
开发语言·c#
¥-oriented1 小时前
【C#中路径相关的概念】
开发语言·c#
CoderCodingNo2 小时前
【GESP】C++四级考试大纲知识点梳理, (7) 排序算法基本概念
开发语言·c++·排序算法
恋猫de小郭2 小时前
Meta 宣布加入 Kotlin 基金会,将为 Kotlin 和 Android 生态提供全新支持
android·开发语言·ios·kotlin
JosieBook2 小时前
【Java编程动手学】使用IDEA创建第一个HelloJava程序
java·开发语言·intellij-idea