perl 模拟curl put请求
来源:互联网 发布:淘宝客怎么帮卖家推广 编辑:程序博客网 时间:2024/05/29 03:00
token=`curl -d "username=015208@zjtlcb.com&password=1234567" http://10.10.17.1:8000/api2/auth-token/ |awk -F ":" '{print $2}' | sed 's/"//g' | sed 's/}//g'`echo $tokencurl -v -X PUT -d "password=123456" -H "Authorization: Token $token" -H 'Accept: application/json; indent=4' http://10.10.17.1:8000/api2/accounts/88888@gmail.com/use LWP::UserAgent; use LWP;use Encode;use LWP::Simple;use LWP::UserAgent;use HTTP::Cookies;use HTTP::Headers;use HTTP::Response;use Encode;use URI::Escape;use URI::URL;use JSON;use Data::Dumper; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0"); my $cookie_jar = HTTP::Cookies->new( file=>'lwp_cookies.txt', autosave=>1, ignore_discard=>1); $ua->cookie_jar($cookie_jar); my $token_url= 'http://127.0.0.1:8000/api2/auth-token/'; my $res = $ua->post($token_url, { 'username'=>'015208@zjtlcb.com', 'password'=>'1234567' }); print $res->content(); print "\n"; my $r= $res->content(); my $r=encode_utf8($r); my $hash = decode_json($r); my $token =$hash->{"token"}; print "\$r is $r\n"; my $host = "http://127.0.0.1:8000/api2/auth/ping/"; @header = ( 'accept'=> "application/json; indent=4", 'content-type'=> "application/x-www-form-urlencoded", 'Authorization'=> "Token $token" ); $host="http://127.0.0.1:8000/api2/accounts/"; $request = HTTP::Request->new(GET=>"$host"); $request->header(@header); $response = $ua->request($request); print $response->decoded_content; my $r=$response->decoded_content;my $r=encode_utf8($r); my $arr = decode_json($r);print "---------------------------\n";foreach $a (@{$arr}){ print $a->{"email"}; print "\n"; };##创建用户 ##"password=1234567" 为put的数据 my $url="http://127.0.0.1:8000/api2/accounts/00528\@zjtlcb.com";push @{$ua->requests_redirectable},'PUT'; $request = HTTP::Request->new(PUT=>$url,HTTP::Headers->new('content-type'=> "application/x-www-form-urlencoded",'accept'=> "application/json; indent=4", 'Authorization'=> "Token $token"),"password=1234567"); $request->header(@header); $response = $ua->request($request); print $response->content; print $response->status_line();print $response->as_string(); # my $response = $ua->put($url, # 'accept'=> "application/json; indent=4", # 'content-type'=> "application/x-www-form-urlencoded", # 'Authorization'=> "Token $token" ,# "password"=>"1234567" # ); # print $response->status_line(); # print $response->as_string();
0 0
- perl 模拟curl put请求
- perl 模拟curl get请求
- perl 模拟curl post请求
- curl模拟delete/put/post/get请求
- perl 模拟curl 自定义请求头
- python perl curl 模拟get请求
- curl perl python 模拟post请求
- PHP中使用CURL模拟发送GET,POST,PUT,DELETE请求
- perl PUT 请求加请求头
- PHP使用curl实现put请求
- curl如何发起DELETE/PUT请求
- PHP - CURL 模拟请求
- cURL模拟POST请求
- CURL模拟post请求
- curl模拟浏览器请求
- curl模拟post请求
- curl模拟post请求
- curl 模拟post请求
- CSRF(跨站请求伪造攻击)漏洞详细说明
- 测试的道理
- 前后台交互积累(一)
- bootstrap——css样式(二、排版)
- RDD依赖关系解密
- perl 模拟curl put请求
- Oracle数据库-存储过程
- python中pass语句学习
- Can't connect to MySQL server on '192.168.1.107' (113)
- 学习笔记——Java中数据类型,对象,传递的通俗理解
- 2017前端性能优化清单
- win7下搭建opengl es 2.0开发环境
- CMTime简单介绍
- 文件的读写