Coinkite API -方法不允许状态:405使用PHP cURL POST -为什么


Coinkite API - Method Not Allowed status: 405 using PHP cURL POST -- Why?

我得到错误:

{"message": "Method Not Allowed", "status": 405}

尝试创建新的接收地址时。根据API文档,我的API密钥具有"recv"权限。

这是API文档中关于向端点发送参数的说明。唯一需要的参数是帐户,我试图在cURLPOST

我怀疑我没有正确设置cURL选项。

下面是我的代码:
$endpoint='/v1/new/receive';
$url='https://api.coinkite.com'.$endpoint;
$sign = coinkitesign($endpoint);
$API_KEY = COINKITEAPIKEY;
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("X-CK-Key: {$API_KEY}", "X-CK-Sign: {$sign[0]}", "X-CK-Timestamp: {$sign[1]}"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array('account' => '933xxxxx2A-Axxxx5','memo' => 'test1234');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

您需要做PUT请求,而不是POST

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

你应该在API文档中反复检查你接受的方法:https://docs.coinkite.com/api/new-update.html

实际上,解决方案是使用put——这是我需要的代码:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
$data = array('account' => 'xxxxxx-xxxxxx','memo' => 'test1234');
$data = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);