PUT请求不适用于PHP

PUT请求不适用于PHP

本文介绍了cURL PUT请求不适用于PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下位置的Challonge.com API: https://api.challonge.com/v1

I am working with the Challonge.com API found here: https://api.challonge.com/v1

我正在尝试使比赛更新功能正常工作- https://api .challonge.com/v1/documents/matches/update

I am trying to get the match UPDATE feature to work - https://api.challonge.com/v1/documents/matches/update

我已经成功使用相同的代码更新了锦标赛,但是由于某些原因,以下代码未更新变量.相反,我得到的响应与脚本运行之前的响应相同.有任何想法吗?

I have had success updating my tournament with the same code, but for some reason the following code is not updating the variables. Instead the response I get is the same as before the script is ran. Any Ideas?

       // 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;

推荐答案

您的文档指出winner_idscores_csv的参数必须是match的数组:

Your documentation states that the parameters for winner_id and scores_csvhave to be an array of 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"
        )
    );

这篇关于cURL PUT请求不适用于PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 23:38