【问题标题】:cURL PUT Request Not Working with PHPcURL PUT 请求不适用于 PHP
【发布时间】:2017-06-16 06:39:13
【问题描述】:

我正在使用位于此处的 Challonge.com API:https://api.challonge.com/v1

我正在尝试使用匹配更新功能 - https://api.challonge.com/v1/documents/matches/update

我已经成功地使用相同的代码更新了我的锦标赛,但由于某种原因,以下代码没有更新变量。相反,我得到的响应与运行脚本之前的响应相同。有什么想法吗?

       // Update Match on Challonge
        $params = array(
            "api_key" => "my api key goes here",
            "winner_id" => "50287554",
            "scores_csv" => "2-5,1-3"               
        );
        $url = "https://api.challonge.com/v1/tournaments/efps_59/matches/78842711.json"; 
        $data_json = json_encode($params);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response  = curl_exec($ch);
        curl_close($ch);
        echo $response;

【问题讨论】:

    标签: php json api curl


    【解决方案1】:

    您的documentation 声明winner_idscores_csv 的参数必须是match 的数组:

       // Update Match on Challonge
        $params = array(
            "api_key" => "my api key goes here",
            "match" => array(
                "winner_id" => "50287554",
                "scores_csv" => "2-5,1-3"
            )
        );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 2020-06-13
      相关资源
      最近更新 更多