【问题标题】:Coinkite API - Method Not Allowed status: 405 using PHP cURL POST -- Why?Coinkite API - 方法不允许状态:405 使用 PHP cURL POST - 为什么?
【发布时间】:2015-09-14 18:10:45
【问题描述】:

我收到错误:

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

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

This 是 API 文档所说的关于将 args 发送到端点的内容。唯一需要的参数是帐户,我在cURL 中尝试POST

我怀疑我没有正确设置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;

【问题讨论】:

    标签: php api curl


    【解决方案1】:

    您需要发出PUT 请求,而不是POST

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

    您应该始终在 API 文档中仔细检查您接受的方法:https://docs.coinkite.com/api/new-update.html

    【讨论】:

      【解决方案2】:

      确实,解决方案是使用 put -- 这是我需要的代码:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-17
        • 2018-10-14
        • 2016-02-15
        • 2014-04-18
        • 1970-01-01
        • 1970-01-01
        • 2015-02-10
        • 2014-05-23
        相关资源
        最近更新 更多