查看Perl笔记的源代码
←
Perl笔记
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== HTTP == === Socket === <source lang=perl> my $body_len = length($body); my $head = << "EOF"; POST /v1/messages HTTP/1.1 Accept: */* xkey: XKEY Content-Length: C_LEN Content-Type: text/html BODY EOF $head =~ s/XKEY/$xkey/g; $head =~ s/C_LEN/$body_len/g; $head =~ s/BODY/$body/g; use IO::Socket; my $sock = new IO::Socket::INET ( PeerAddr => 'api.google.com', PeerPort => '9999', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock; print $sock $head; print while <$sock>; close ($sock); </source> <br><br> === LWP Simple === <source lang=perl> use LWP::Simple; use JSON; my $content = get "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET"; die "Couldn't get" unless defined $content; my $tmp = from_json($content); ...... </source> <b>LWP::Simple 的 post 需要额外的包:/usr/share/perl5/LWP/Simple/Post.pm</b> <source lang=perl> use LWP::Simple::Post qw(post post_xml); use JSON; my $ticket_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN"; my $req = "{\"action_name\":\"QR_LIMIT_SCENE\",\"action_info\": {\"scene\": {\"scene_id\": $param}}}"; my $ret = post($ticket_url, $req); my $t = from_json($ret); </source> <br><br> === LWP UserAgent === <source lang=perl> use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent("XXL/1.0"); my $req = HTTP::Request->new(POST => 'http://api.google.com:888/v2.0/node'); $req->header(Accept => "*/ *"); $req->header(nodid => "$uuid"); $req->header(token => "$token"); $req->header(type => "x1"); $req->content_type('text/html'); $req->content($body); my $ret = $ua->request($req); my $ct = $ret->content; if ($ret->is_success) { print STDERR $ct; } else { print STDERR $ret->status_line . "\t" . $ct; } </source> <br><br>
返回到
Perl笔记
。
个人工具
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面