zoukankan      html  css  js  c++  java
  • perl 模拟curl 自定义请求头

    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 "
    ";
       my $r= $res->content();
       my $r=encode_utf8($r);
       my $hash = decode_json($r);
       my $token =$hash->{"token"};
       print "$r is $r
    ";
       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;  
     


    
                                        
    
  • 相关阅读:
    SpringBoot与thymeleaf
    动态控制页面的隐藏显示
    javascript执行顺序小结
    利用VBA Hack掉Excel的保护密码
    ARP欺骗与MITM(中间人攻击)实例
    大牛博客收藏
    Linux 基础命令
    系统引导UEFI 引导,Win下挂载EFI分区教程
    【ACM】【Pro.1000】A + B Problem ACM之旅开始啦
    vue中解决拖拽改变存在iframe的div大小时卡顿问题
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349915.html
Copyright © 2011-2022 走看看