【问题标题】:token request with Perl an Net::SSLeay使用 Perl 和 Net::SSLeay 的令牌请求
【发布时间】:2013-03-05 12:14:28
【问题描述】:

我正在尝试使用 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"
));

这里有人可以帮忙吗?

最好的问候, 拉尔斯

【问题讨论】:

  • 请显示错误代码!

标签: perl api rest paypal


【解决方案1】:

您需要对字符串user:password 进行base64,而不是单独进行。所以在你的例子中应该是:

my $uname = "EN_Qsr0vnzjAI8iixqZHd2yoNtIZYDkdAreSpqbe3SiU";
my $password ="EDQccsa77f81xM-QU9kADtioNtIZYDkdAreSpqbe3SiU";

my $cred = "Basic " . encode_base64($uname . ":" . $password);

【讨论】:

    猜你喜欢
    • 2011-10-11
    • 2015-01-31
    • 2018-11-27
    • 1970-01-01
    • 2018-08-30
    • 2016-06-11
    • 2022-09-24
    • 2017-04-17
    • 2011-09-05
    相关资源
    最近更新 更多