use URI::Escape;#URL编码
use JSON;
#发送GET请求
use LWP::Simple;
my $tmp = "您本次操作的验证码为:$code";
my $smsmsg = uri_escape_utf8($tmp); #URL编码
my $args="http://xxx?p=".$phone."&c=$smsmsg";
my $response = get($args);
或者:
use HTTP::Request;
use HTTP::Headers;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10); #设置超时时间10s, 默认是180s
my $header = HTTP::Headers->new( Content_Type => 'text/html; charset=utf8', ); #设置head
$request = HTTP::Request->new('GET', $url, $header);
my $response = $ua->request($request);
my $res = "";
if ($response->message ne "OK" && $response->is_success ne "1") { #出错,或者timeout了
$res = "error or timeout";
} else {
$res = decode("utf-8",$response->content);
}
#发送POST请求
use HTTP::Request;
use HTTP::Headers;
use LWP::UserAgent;
use JSON;
my $url="http://xxx?p=".$phone."&c=$smsmsg";
my $json = JSON->new();
my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new('POST', $url);
my $response = $ua->request($req);
my $ret = $json->decode($response->decoded_content());
#复杂点的,PSOT内容为xml格式,请求为https
my $request_xml = create_xml_data($tmp); #构造 xml格式的字符串
my $header = HTTP::Headers->new( Content_Type => 'text/xml; charset=utf8', );
my $http_request = HTTP::Request->new( POST => "https://xxx", $header, $request_xml);
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0, SSL_verify_mode => 0x00 });
my $response = $ua->request($http_request);
# PSOT内容为JSON格式
my $header = HTTP::Headers->new( Content_Type => 'application/json; charset=utf8', );
my $param_json_str =$json->encode($post_data); #构造JSON格式的字符串
my $http_request = HTTP::Request->new( POST => "https://xxxxx", $header, $param_json_str );
#特殊POST, https服务器需要客户端上传证书
#以微信现金红包发放API为例,https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
#证书说明:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3
#
my $header = HTTP::Headers->new( Content_Type => 'text/xml; charset=utf8', );
my $http_request = HTTP::Request->new( POST => "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack", $header, $request_xml);
my $ua = LWP::UserAgent->new(
ssl_opts => {
verify_hostname => 0,
#SSL_verify_mode => 0x00,
#SSL_ca_file => '/var/wechat/rootca.pem' # 如果客户端也要去验证微信服务器,则需要导入CA证书
SSL_use_cert => 1,
SSL_cert_file => '/var/wechat/apiclient_cert.pem', # 证书文件pem格式
SSL_key_file => '/var/wechat/apiclient_key.pem', # 证书密钥pem格式
SSL_passwd_cb => sub { $config->{mch_id} },# 证书密码
},
);
my $response = $ua->request($http_request);
#特殊POST,服务器要求Content-Type: application/x-www-form-urlencoded格式post
#必须采用下列方式,因为接口要求Content-Type: application/x-www-form-urlencoded
#参考perl网站:https://metacpan.org/pod/HTTP::Request::Common
use HTTP::Request::Common
use LWP::UserAgent;
use JSON;
方式一:
my $response = $ua->request(POST 'https://xxxxx',
[
distributionid => $ID,
distributionkey => $KEY,
request_type => 1,
send_type => 1,
industry => "互联网/电子商务",
sent_way => 3,
merchants => "xxxx",
device_id => "9823413111"
]
);
方式二:
my $params = {
distributionid => $ID,
distributionkey => $KEY,
request_type => 1,
send_type => 1,
industry => "互联网/电子商务",
sent_way => 3,
merchants => "xxxx",
device_id => "9823413111"
};
my $tmp = join( '&',
map { sprintf( '%s=%s', $_, $params->{$_} ) }
sort { $a cmp $b } keys %$params );
my $content = uri_escape_utf8($tmp); # 区别于方式一,这里需要自行做urlencode
my $header = HTTP::Headers->new( Content_Type => 'application/x-www-form-urlencoded; charset=utf8', );
my $http_request = HTTP::Request->new( POST => 'https://xxxxx', $header, $content );
my $ret;
if ($response->message ne "OK" && $response->is_success ne "1") {
$ret->{msg} = "error";
} else {
my $json = JSON->new();
$ret = $json->decode($response->decoded_content());
}
# 使用代理方式发送请求
$ua->timeout(2);
$ua->proxy(['http'], "http://$proxyAddr"); # $proxyAddr 可以是ip加端口例如 "172.1.1.1:128", 相应的也可以用https代理
# 添加http协议头
my @header = ( "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Charset" => "utf-8, iso-8859-1, utf-16, *;q=0.7",
"User_Agent" => "Mozilla/5.0 (Linux; U; Android 6.0.1; zh-cn; MI 3W Build/MMB29M)",
"X-Requested-With" => "com.android.browser",
#"X-Forward-For" => $ip
);
my $req = HTTP::Request->new( GET => $url);
$req->header(@header);
my $response = $ua->request($req);
相关推荐
名称 pureproxy-Pure Perl HTTP代理服务器 ...http_proxy=http://localhost:5000/ lwp-request http://www.perl.org/ https_proxy=http://localhost:5000/ lwp-request https://metacpan.org/ 描述 这是纯Perl HTTP
Apache::args Versus Apache::Request::param Versus CGI::param Section 13.3. Buffered Printing and Better print( ) Techniques Section 13.4. Interpolation, Concatenation, or List Section ...
Google Calendar Perl访问 它包含一个库( calendar_functions.pl ),该库可... get_request() access_token() is_booked() get_bookings() get_calendar_list_data() get_calendar_id() 有一个Bour
需要模块HTTP :: Request :: Common,LWP :: UserAgent和JSON。 松弛颠覆 将提交消息从Subversion发布到Slack集成以进行Subversion。 Slack网站上的集成中指定了通知转到的渠道,因此可能为不同的回购定义了多个...
* tools to request or set information from SNMP agents * tools to generate and handle SNMP traps * a version of the unix netstat command using SNMP * a graphical Perl/Tk/SNMP based mib browser
HTTP :: Request; LWP :: Simple; Cwd; 平行的:: ForkManager; 用法:perl script.pl example.com/path/to/images文件夹 url:您要转储的博客的URL文件夹:您要存储图像的文件夹 待办事项:如果重复的图像(按...
通常,您将需要构造HTTP::Request或HTTP::Response对象。 可选的$ header参数应该是对HTTP::Headers对象的引用,或者是键/值对的纯数组引用。 如果提供了HTTP::Headers对象,则其副本将被嵌入到构造的消息中,即它...
perldoc Text::ProgressBar您还可以在以下位置查找信息: RT, CPAN's request tracker (report bugs here) http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-ProgressBarAnnoCPAN, Annotated CPAN documentation ...
rt4vagrant:Request Tracker的Vagrant开发环境
npm installnpm run serve对于Perl数据库: cpanm AnyEvent Coro::Twiggy Plack::Request Data::Dumper::Perltidy Graph Graph::D3perl storage.pl这到底是什么? 这是我的个人笔记工具,经过数年与TreeSheets,yEd...
Turnitin-lti-perl 访问 Turnitin LTI 服务的 Perl 接口 The LTI gateway accepts SOAP and LTI calls. SOAP The request is a well-formed XML file, and the response is an XML file. The exact syntax is ...
rt:Request Tracker,企业级问题跟踪系统
Perl 依赖项HTTP::Request::Common LWP YAML Proc::Daemon配置提供了一个示例 rundeck.yml 配置文件,可以放入 /etc 您需要将 node1 node2 替换为您服务器的真实名称,并添加来自 Rundeck 集群中每个主机的 UUID。...
use HTTP::Request::Common; use Test::More; use Test::JsonAPI::Autodoc; # JSON request describe 'POST /foo' => sub { my $req = POST 'http://localhost:5000/foo'; $req->header('Content-Type' => '...
网址::请求Web :: Request与CGI.pm或Perl 5中的Plack :: Request相似。 它支持P6SGI 0.7Draft(推荐),P6SGI 0.4Draft,PSGI Classic,SCGI独立,FastCGI独立和mod-perl6。 可以强制使用标准CGI,但实际上不
perl Makefile.PL make make test make install 支持和文档 安装后,您可以使用perldoc命令找到此模块的文档。 perldoc Dezi 您也可以在以下位置查找信息: RT, CPAN's request tracker ...
Hatena::Newbie::Request从继承的Hatena::Newbie::Request Hatena::Newbie::Request $c->req->parameters->{$key} 返回与$key对应的请求参数 所有参数(例如查询参数和通过路由获得的参数)都是目标。 $c->dbh 返回...
文件轮换日志 提供一个io.Writer从应用程序中定期轮换日志文件。 从 Perl 到 Go 的端口。... HandleFunc ( "/" , func ( w http. ResponseWriter , r * http. Request ) { ... }) logf , err := rotatelo
OTOBO扩展机票通知 专... 基于 使用Perl / CPAN模块 JSON::MaybeXS LWP::UserAgent HTTP::Request::Common Data::DumperOTOBO代理首选项(配置文件): OTOBO票务通知设置: 电报对于松弛对于RocketChat待办的
jiraRESTbridge JIRA REST API 桥接器要求: Optconfig LWP JSON Crypt::OpenSSL::RSA URI CGI HTTP::Request MIME::Base64 Digest::SHA1 Net::OAuth 安装: Apache2 配置: <Location> Options +ExecCGI AddHandler...