我在perl脚本中运行curl请求,如果密码或用户名包含任何特殊字符(&),则会破坏该url。请让我知道如何解决这个问题。
my $json="curl --user $userName:$password http://git.sample.com/rest/api/1.0/projects/TEAMS/repos/ ";
my $decodedJson = decode_json($json);
答案 0 :(得分:1)
最后,我使用WP::UserAgent
实现了@simbabque方式。
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request(GET => 'http://git.sample.com/rest/api/1.0/projects/TEAMS/repos/');
$req->authorization_basic($userName,$password);
my $response = $ua->request($req);
#handle error
unless ($response->is_success) {
die $response->status_line;
}
my $content = $response->decoded_content();
if (utf8::is_utf8($content)) {
binmode STDOUT,':utf8';
} else {
binmode STDOUT,':raw';
}
my $json=$content;
my $decodedJson = decode_json($json);