【问题标题】:php api Unauthorized request json rpc 2.0php api 未经授权的请求 json rpc 2.0
【发布时间】:2020-05-26 16:14:00
【问题描述】:

我想使用正确的 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】:

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

    【讨论】:

      猜你喜欢
      • 2012-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多