【问题标题】:How to set 'grant type' with lwp如何使用 lwp 设置“授权类型”
【发布时间】:2014-10-23 21:08:16
【问题描述】:

我正在尝试使用 LWP::UserAgent 连接到服务器。我已经成功地在同一台服务器上使用 LWP::UserAgent 进行匿名搜索,但现在我必须“秘密”一些东西,这需要在该服务器上使用身份验证。我已经使用了代码:

my $ua = LWP::UserAgent->new;
$ua->default_header('Content-Type'  => "application/x-www-form-urlencoded");
$ua->default_header('Authorization' => "Basic ".$Authent);
my $resp  = $ua->post($uri);

服务器响应:错误 400,必需参数:grant_type

那么,如何使用 LWP 设置 Grand 类型参数? 我还没有找到任何关于大字体问题的页面。

我也试过了:

$ua->default_header('grant_type'    => "client_credentials");

my $resp  = $ua->post($uri, grant_type => "client_credentials");

所有三个都给出完全相同的错误消息。 我不知道如何让事情顺利进行。

【问题讨论】:

标签: perl lwp-useragent


【解决方案1】:

TA-DAA!我找到了答案。

grant_type 不是 header 的东西,它属于 body。 所以,这样做的工作方式是:

$ua->default_header('Content-Type'  => "application/x-www-form-urlencoded");
$ua->default_header('Authorization' => "Basic ".$Authent);
my $resp  = $ua->post($uri, Content => ['grant_type' =>  "client_credentials"]);

还是谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-02
    • 2021-03-03
    • 2018-01-28
    • 2018-07-05
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多