• perl post 上传文件


    ###列出组信息
    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;
      if ( $#ARGV < 3 ){  
            print "please input your  username password  file repo_id!
    ";
    		print "just like 015208  1234567   aa.txt  'a3333a72-bb7f-477a-a7ed-7b05b029a9b9' ";
            exit(-1);
    		};
      my $username=$ARGV[0];
      my $password=$ARGV[1];
      my $file=$ARGV[2];
      my $repo_id=$ARGV[3];
      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://10.5.100.241:8000/api2/auth-token/';
                    
      
       my $res = $ua->post($token_url,
                    {
                    'username'=>"$username@zjtlcb.com",
                    'password'=>"$password"
                    });
       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
    ";
      
       @header = (  
        'accept'=> "application/json",  
        'content-type'=> "application/json",  
        'Authorization'=> "Token $token" 
        );  
    	#GEThttps://cloud.seafile.com/api2/repos/{repo-id}/upload-link/
        #curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" https://cloud.seafile.com/api2/repos/99b758e6-91ab-4265-b705-925367374cf0/upload-link/
        $host="http://10.5.100.241:8000/api2/repos/$repo_id/upload-link/";  
        $request = HTTP::Request->new(GET=>"$host");  
        $request->header(@header);  
      
        $response = $ua->request($request);  	
        #print $response->decoded_content;  
        
    	my $upload_link=$response->decoded_content;
    	#$upload_link =~ s/upload-api/upload-aj/;
    	chomp $upload_link;
    	print $upload_link;
    	print "
    ";
        #curl -H "Authorization: Token 262a8daefa5eb52ea5eaf71688965843b7b0ad20" -F file=@aa.txt -F filename=aa.txt -F parent_dir=/ http://10.5.100.241:8082/upload-api/e0f952df-53dd-4f6d-b803-ae3df1f6c561
    	
    	
    	my $url=$upload_link;
        my $res = $ua->post($url, 
    	 
        'content-type'=> "form-data",	 
        'Authorization'=> "Token  $token" ,
    	#Content =>[pageAction='upload',filename =>['aa.txt']]
    	#Content =>[parent_dir=>"/",filename =>["D:\api\scripts\aa.txt"]]
    	
    	Content =>[file =>[$file], parent_dir=>'/']
    	
    				);
        print "---------------------------
    ";
        print $res->content(); 
       # print $response->status_line();
       #system("curl -H "Authorization: Token 262a8daefa5eb52ea5eaf71688965843b7b0ad20" -F file=@aa.txt -F filename=aa.txt -F parent_dir=/ http://10.5.100.241:8082/upload-api/c49fdc5e-ab3f-4e2a-968d-46ccfa587683");
    
    
    
    
    	
    
    D:apiscripts>perl get_upload_file.pl 015208 1234567 xx.txt  a3333a72-bb7f-477a
    -a7ed-7b05b029a9b9
    {"token": "262a8daefa5eb52ea5eaf71688965843b7b0ad20"}
    $r is {"token": "262a8daefa5eb52ea5eaf71688965843b7b0ad20"}
    "http://10.5.100.241:8082/upload-api/8f3e38e9-5cd6-4954-809f-df29ee1cecf2"
    ---------------------------
    0000000000000000000000000000000000000000
    D:apiscripts>
    
    
    a3333a72-bb7f-477a-a7ed-7b05b029a9b9---------tailong
    301ccb82-827b-46e4-80aa-178aad7d46e9---------scan
    47694e3a-0969-4dbc-bb1c-935dd46b3cc8---------赵杨健
    87cc2996-cc2e-4b8b-8d48-5896da24654b---------My Library
    301ccb82-827b-46e4-80aa-178aad7d46e9---------scan

  • 相关阅读:
    Vue 冷知识(一)
    Google Chrome 谷歌浏览器 调试被坑之路
    全选、全不选、反选
    赋值运算符
    JS 数组的常用方法归纳之不改变原数组和其他
    CSS控制文字,超出部分显示省略号
    火狐浏览器解决跨域问题
    JS 数组的常用方法详解归纳之改变原数组方法
    vue项目 多文件上传并显示在页面上
    二叉搜索树操作
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349904.html
Copyright © 2020-2023  润新知