1

I am using the following code:

<?php

$url = "https://api.challonge.com/v1/tournaments/hamiltonjenn/matches/245771359.json";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_PUT, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "Accept: application/json",
   "Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
   "Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$data = '{"match":{"player1_votes": 4}}';

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);

?>

var_dump shows only bool(false)

Any ideas why this is happening? I cannot determine the reason this won't work.

  • See if anything on https://stackoverflow.com/questions/3757071/php-debugging-curl helps. – Nigel Ren Aug 02 '21 at 05:46
  • 2
    You also need to send headers as `content-type:application/json`? Also see this for `CURLOPT_PUT` https://stackoverflow.com/questions/44918152/curlopt-put-vs-curlopt-postfields – nice_dev Aug 02 '21 at 06:02
  • @nice_dev is that not what I'm doing on the line that reads: "Content-Type: application/json", ? – Jennifer Hamilton Aug 02 '21 at 06:18
  • 2
    turns out just changing curl_setopt($curl, CURLOPT_PUT, true); to curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); solved the problem. Thanks for the link @nice_dev – Jennifer Hamilton Aug 02 '21 at 06:22
  • @JenniferHamilton Ahh, overlooked that. Glad to help – nice_dev Aug 02 '21 at 06:36

1 Answers1

0

I'm not sure why, but changing the curl_setopt($curl, CURLOPT_PUT, true); to curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); solved the issue. I'm gathering that CURLOPT_PUT, true is expecting a file, whereas CURLOPT_CUSTOMREQUEST, "PUT" is expecting an update to the string.