【发布时间】: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);
【问题讨论】: