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});
相关推荐
json{shen:"jing"}2 小时前
js收官总概述
开发语言·python
froginwe112 小时前
Java 文档注释
开发语言
Zsy_0510032 小时前
【C++】stack、queue、容器适配器
开发语言·c++
一起努力啊~2 小时前
算法刷题--栈和队列
开发语言·算法
万行2 小时前
SQL进阶&索引篇
开发语言·数据库·人工智能·sql
打工的小王2 小时前
java并发编程(六)CountDownLatch和回环屏障CyclicBarrier
java·开发语言
星火开发设计2 小时前
命名空间 namespace:解决命名冲突的利器
c语言·开发语言·c++·学习·算法·知识
小北方城市网2 小时前
RabbitMQ 生产级实战:可靠性投递、高并发优化与问题排查
开发语言·分布式·python·缓存·性能优化·rabbitmq·ruby
爱学习的阿磊2 小时前
C++中的策略模式应用
开发语言·c++·算法
郝学胜-神的一滴2 小时前
Python中的bisect模块:优雅处理有序序列的艺术
开发语言·数据结构·python·程序人生·算法