Parse platform 按完成的方式更新报告,但不会发生
使用Parse.com和RESTAPI。我正在发送PUT请求以更新记录Parse platform 按完成的方式更新报告,但不会发生,parse-platform,Parse Platform,使用Parse.com和RESTAPI。我正在发送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 , ); $object
$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字段实际上是update。事实上,这是唯一得到更新的东西!
如果我从url输入objectId,并使用POST而不是PUT,插入效果就很好。方法是使用infle而不是POSTFIELDS,以便为url传递数据thx
不用说,确切的curl shell命令非常有效。与您的问题无关,但请不要执行此curl\u setopt$rest,CURLOPT\u SSL\u VERIFYPEER,false;:
$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);