无法将PUT从命令行转换为php

时间:2014-07-16 17:51:56

标签: php curl parse-platform put

我无法将PUT curl命令转换为php。我刚刚想出如何将POST方法转换为PHP,但是我在使用PUT更新Parse.com上的数据库时遇到了困难。

这是我的卷曲声明:

  curl -X PUT \
  -H "X-Parse-Application-Id: app id" \  
  -H "X-Parse-REST-API-Key: rest api"   
  -H "Content-Type: application/json"   
  -d '{"site_status":"statusValue"}'   
  https://api.parse.com/1/classes/MyClass/objectId 

(已解决):信息正在更新为Parse !!!

<?php 

 $ch = curl_init('https://api.parse.com/1/classes/ClientCompanyInfo/objectID');

  curl_setopt($ch,CURLOPT_HTTPHEADER,
      array('X-Parse-Application-Id:app_id',
      'X-Parse-REST-API-Key:rest_api_id',
      'Content-Type: application/json'));

 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"PUT");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"site_status\":\"siteValueStatus\"}");

 curl_exec($ch);
 curl_close($ch);

?>

1 个答案:

答案 0 :(得分:1)

试一试:

$headers = array(
  'X-Parse-Application-Id: app_id',
  'X-Parse-REST-API-Key: rest_key',
  'Content-Type: application/json'
);
$url = 'https://api.parse.com/1/classes/MyClass/objectId';
$changes = array(
  'site_status' => 'statusValue'
);
$rest = curl_init();
curl_setopt($rest, CURLOPT_URL, $url);
curl_setopt($rest, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($rest, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rest, CURLOPT_HTTPHEADER, $headers);
curl_setopt($rest, CURLOPT_POSTFIELDS, http_build_query($changes));
$response = curl_exec($rest);
curl_close($rest);
var_dump($response);