频道栏目
首页 > 资讯 > Linux > 正文

perl 模拟curl post请求

17-01-18        来源:[db:作者]  
收藏   我要投稿

perl 模拟curl post请求。

<pre code_snippet_id="2134758" snippet_file_name="blog_20170117_1_8791280" name="code" class="html">obtain auth token  
  
curl -d "username=username@example.com&password=123456" https://cloud.seafile.com/api2/auth-token/  
  
{"token": "24fd3c026886e3121b2ca630805ed425c272cb96"}  
  
  
  
curl -d 说明:  
  
  
       -d/--data <data>  
              (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit  button.  This  will  
              cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded.  Compare to -F/--form.  
  
              -d/--data is the same as --data-ascii. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form field you may use --data-urlencode.  
  
              If  any  of  these  options  is  used  more than once on the same command line, the data pieces specified will be merged together with a separating &-symbol. Thus, using ’-d name=daniel -d  
              skill=lousy’ would generate a post chunk that looks like ’name=daniel&skill=lousy’.  
  
              If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin.  The contents of the file must already  be  
              URL-encoded. Multiple files can also be specified. Posting data from a file named ’foobar’ would thus be done with --data @foobar.  
  
  
  
(HTTP)发送指定的数据 以一个POST 请求到HTTP SERVER, 在浏览器中 当一个用户已经填写HTML 表单和按下提交按钮。  
  
这个导致curl 来传递数据到server 使用 content-type application/x-www-form-urlencoded.  
  
  
相比 -F/--form. -d/--data is the same as --data-ascii  
  
  
post 数据纯2进值, 为了 URL-encode 表单字段的值 你可以使用--data-urlencode.  
  
         
  
  
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);  
   print $hash->{"token"};</pre><br>  
<br>  
<pre></pre>  

 

相关TAG标签
上一篇:Linux 在 linux 中搭建 FTP 服务
下一篇:HTML入门学习笔记--CSS3D转换模块和背景相关(12)
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站