EDIT: For some reason, this server is expecting a header 'Accept: application/json'
. When I added that, it worked fine.
I have tried several different ways to do a PUT request with a JSON request body. I always get an error saying that they didn't receive the data. I don't know if it's my code or their server. This is what I have now. Also, I have tried every combination of curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
and curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
and nothing works.
However I get an error sending the exact same data using the following PHP
$curl = curl_init();
$data = json_encode($data_array);
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data));
$headers[]= 'Authorization: Basic '.AUTHENTICATION_TOKEN;
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, $url);
$result = curl_exec($curl);