我正在尝试使用Perl和Net :: SSLeay请求新REST API的令牌(我的提供商仅支持Net :: SSLeay,未安装NET :: PayPal等模块)但请求失败。我究竟做错了什么?特别是我不确定,设置'grant_type'很热......
use Net::SSLeay qw(get_https make_form make_headers post_https);
use MIME::Base64;
use strict;
my $site = "api.sandbox.paypal.com";
my $port = "443";
my $path = "/v1/oauth2/token?grant_type=client_credentials";
my $uname = "my_client_id";
my $password = "my_secret";
$uname = encode_base64($uname);
$password = encode_base64($password);
my $cred = "Basic $uname:$password";
my ($page, $result, %headers) = post_https($site, $port, $path, make_headers(
'Accept'=>"application/json",
'Accept-Language'=>"en_US",
'Authorization'=>"$cred"
));
这里有人可以帮忙吗?
祝你好运, 拉斯
答案 0 :(得分:0)
你需要base64字符串user:password
,而不是单独的。所以在你的例子中它应该是:
my $uname = "EN_Qsr0vnzjAI8iixqZHd2yoNtIZYDkdAreSpqbe3SiU";
my $password ="EDQccsa77f81xM-QU9kADtioNtIZYDkdAreSpqbe3SiU";
my $cred = "Basic " . encode_base64($uname . ":" . $password);