2017-07-17 4 views
0

私のperlスクリプト内でカール要求を実行し、パスワードまたはユーザー名に特殊文字(&)が含まれていると、URLが破損します。どうすれば解決できるか教えてください。パスワードに特殊文字が含まれており、URLが壊れています

my $json="curl --user $userName:$password http://git.sample.com/rest/api/1.0/projects/TEAMS/repos/ "; 

my $decodedJson = decode_json($json); 
+2

'WWW :: Curl'代わりのCMDLINEコール私はネイティブな方法 – Jens

+0

Perlでのネイティブな方法は、カールを使用しないことだろうが、LWPを使用するようにPerlモジュールを使用して:: UserAgentが代わりに。 – gihan

+5

を探しています – simbabque

答えて

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); 
関連する問題