更新报告已完成,但没有发生

Update reports as done but it doesn't happen

使用 Parse.com 和 REST API。我正在发送 PUT 请求以更新记录。

$url = 'https://api.parse.com/1/classes/Language/lXn2Jr8g3D';  
$headers = array(  
  "Content-Type: application/json",  
  "X-Parse-Application-Id: " . $appId,  
  "X-Parse-REST-API-Key: " . $apiKey ,
);  
$objectData = '{"designation":"barfoo", "order":6}';  
$rest = curl_init();  
curl_setopt($rest,CURLOPT_URL,$url);  
curl_setopt($rest,CURLOPT_PUT,1);  
curl_setopt($rest,CURLOPT_POSTFIELDS,$objectData);  
curl_setopt($rest,CURLOPT_HTTPHEADER,$headers);  
curl_setopt($rest,CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);  
$response = curl_exec($rest);  
echo $response;  
curl_close($rest); 

此报告

{"updatedAt":"2015-02-09T22:28:57.676Z"}

我看到了记录,但没有看到我要求的更改。但是 updatedAt 字段确实是更新的。事实上,这是唯一得到更新的东西! 如果我从 url 中省略 objectId 并使用 POST 而不是 PUT,则插入工作正常。

要走的路是使用 INFILE 而不是 POSTFIELDS 来传递数据(感谢 sample code)。

$url = 'https://api.parse.com/1/classes/Language/lXn2Jr8g3D';  
$headers = array(  
  "Content-Type: application/json",  
  "X-Parse-Application-Id: " . $appId,  
  "X-Parse-REST-API-Key: " . $apiKey ,
);  
$objectData = '{"designation":"barfoo", "order":6}';
// ADDED THIS ---------------------------------------------
//trasnform string to file
$dataAsFile = tmpfile(); 
fwrite($dataAsFile, $objectData); 
fseek($dataAsFile, 0); 
// THIS ADDED ---------------------------------------------


$rest = curl_init();  
curl_setopt($rest,CURLOPT_URL,$url);  
curl_setopt($rest,CURLOPT_PUT,1);  
// REPLACED THIS ---------------------------------------------
// curl_setopt($rest,CURLOPT_POSTFIELDS,$objectData);  
curl_setopt($rest, CURLOPT_INFILE, $dataAsFile); 
curl_setopt($rest, CURLOPT_INFILESIZE, strlen($objectData));
// THIS REPLACED ---------------------------------------------
curl_setopt($rest,CURLOPT_HTTPHEADER,$headers);  
curl_setopt($rest,CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);  
$response = curl_exec($rest);  
echo $response;  
curl_close($rest);