zoukankan      html  css  js  c++  java
  • 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 JSON::backportPP;
    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",
    	'Charset'=>"UTF-8"
        );  
    
        $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;
    	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 =>[file =>[$file,encode("utf8",decode("gbk",$file)),@header], 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");
    	

  • 相关阅读:
    [ASP.NET] Session 一些比较详细的知识(转自:http://blog.csdn.net/zhoufoxcn/archive/2006/11/08/1373685.aspx)
    ASP.NET2.0服务器控件之Render方法 (作者: 金属边缘 出处: 天极开发 )
    [Tip: word pdf] Word Save As PDF
    [Tip: Visual Studio]创建键盘快捷方式速查表
    [Tip: iShare Site] Move file/folder on iShare Site
    google的C++单元测试框架gtest
    XP and Win7 双系统安装教程
    Tip:How to Compact a PST File to Reduce Its Size in Outlook
    [Tip: Perforce]ModTime
    [Tool: fast copy cmd]ROBOCOPY
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349903.html
Copyright © 2011-2022 走看看