###列出组信息
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");