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});
相关推荐
小浣熊熊熊熊熊熊熊丶5 小时前
《Effective Java》第25条:限制源文件为单个顶级类
java·开发语言·effective java
啃火龙果的兔子6 小时前
JDK 安装配置
java·开发语言
星哥说事6 小时前
应用程序监控:Java 与 Web 应用的实践
java·开发语言
等....6 小时前
Miniconda使用
开发语言·python
zfj3216 小时前
go为什么设计成源码依赖,而不是二进制依赖
开发语言·后端·golang
醇氧6 小时前
org.jetbrains.annotations的@Nullable 学习
java·开发语言·学习·intellij-idea
Java&Develop6 小时前
Aes加密 GCM java
java·开发语言·python
weixin_462446236 小时前
使用 Go 实现 SSE 流式推送 + 打字机效果(模拟 Coze Chat)
开发语言·后端·golang
JIngJaneIL7 小时前
基于springboot + vue古城景区管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
敲敲了个代码7 小时前
隐式类型转换:哈基米 == 猫 ? true :false
开发语言·前端·javascript·学习·面试·web