我想使用正确的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);
[Okey我的客户犯了一个错误,并且api密钥是错误的,所以至少这是如何在协议jsonrpc 2.0中使用php的正确方法