perl 模拟curl 自定义请求头
2017-01-17 19:46
369 查看
auth ping curl -H 'Authorization: Token 24fd3c026886e3121b2ca630805ed425c272cb96' https://cloud.seafile.com/api2/auth/ping/ "pong" -H/--header <header> (HTTP) Extra header to use when getting a web page. You may specify any number of extra headers. Note that if you should add a custom header that has the same name as one of the internal ones curl would use, your externally set header will be used instead of the internal one. This allows you to make even trickier stuff than curl would normally do. You should not replace internally set headers without knowing perfectly well what you’re doing. Remove an internal header by giving a replacement without content on the right side of the colon, as in: -H "Host:". curl will make sure that each header you add/replace is sent with the proper end-of-line marker, you should thus not add that as a part of the header content: do not add newlines or car- riage returns, they will only mess things up for you. See also the -A/--user-agent and -e/--referer options. This option can be used multiple times to add/replace/remove multiple headers. (HTTP) 额外的header 来使用当 请求一个web 页面,你可以指定任何数量的额外请求头。 注意,如果你可以增加一个自定义的请求头 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; 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", 'content-type'=> "application/json", 'Authorization'=> "Token $token" ); $host="http://127.0.0.1:8000/api2/auth/ping/"; $request = HTTP::Request->new(GET=>"$host"); $request->header(@header); $response = $ua->request($request); print $response->decoded_content;
相关文章推荐
- curl模拟数据请求,在header头中设置自定义的参数
- perl 模拟curl post请求
- curl perl Python post 发送自定义请求头
- curl_multi_init 模拟并发请求
- Linux 下curl模拟Http 的get or post请求
- Linux 下模拟Http 的get or post请求(curl和wget两种方法)
- perl 自定义请求头
- curl 模拟get和post请求
- curl模拟post请求提交
- Linux 下curl模拟Http 的get or post请求
- Linux 下curl模拟Http 的get or post请求
- Linux下模拟http的get/post请求(curl or wget)
- 模拟get和post请求(支持自定义header和测试CDN节点)
- Linux下模拟http的get/post请求(curl or wget)
- curl模拟post请求提交
- 网络编程(自定义图形界面浏览器-Tomcat服务端). 模拟IE 的请求
- curl 浏览器模拟请求实战
- PHP - CURL 模拟请求
- Linux 下curl模拟Http 的get or post请求。
- curl模拟post请求提交