php api未经授权的请求json rpc 2.0

问题描述 投票:1回答:1

我想使用正确的api密钥访问api,但仍未获得未经授权的错误401。使用JSON RPC 2.0的API。

这是来自api文档的示例请求。

Request:
{
  "jsonrpc": "2.0",
  "method": "getBoards",
  "params": {
       "clientId": "apikey"
 },
 "id": 1
}

这是我的PHP代码。

$apiKey = 'apikey';
$apiUrl = 'apiUrl';

$data =  array(
        "jsonrpc" => "2.0",
        "method" => "getBoards",
        "params" => array(
            "clientId" => $apiKey
        ),
        "id" => "1"
);

$data_string = json_encode($data);
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

$response = curl_exec($ch);
curl_close($ch);

print_r($response);
php api json-rpc
1个回答
0
投票

[Okey我的客户犯了一个错误,并且api密钥是错误的,所以至少这是如何在协议jsonrpc 2.0中使用php的正确方法

© www.soinside.com 2019 - 2024. All rights reserved.