gihan-maduranga
gihan-maduranga

Reputation: 4811

Special character are contained in password and it breaks the URL

I run a curl request within my perl script and if password or user name contains any special character(&) it break the url. Please let me know how can i solve this.

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

my $decodedJson = decode_json($json); 

Upvotes: 0

Views: 336

Answers (1)

gihan-maduranga
gihan-maduranga

Reputation: 4811

Finally i implemented @simbabque way using WP::UserAgent.

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); 

Upvotes: 1

Related Questions