将PUT从命令行转换为php时出现问题
将PUT curl命令转换为php时遇到问题。我刚刚了解了如何将POST方法转换为PHP,但我在Parse.com上使用PUT更新数据库时遇到了困难 这是我的声明:将PUT从命令行转换为php时出现问题,php,curl,parse-platform,put,Php,Curl,Parse Platform,Put,将PUT curl命令转换为php时遇到问题。我刚刚了解了如何将POST方法转换为PHP,但我在Parse.com上使用PUT更新数据库时遇到了困难 这是我的声明: 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":"statu
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
(已解决):正在更新信息以进行解析
<?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);
?>
试一试:
$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);
也。。。在接下来的几周里,请留意一些解析PHP的新闻。我添加了代码,但数据库中没有任何更改。我添加了curl_exec($rest);为了摆脱我犯下的错误。你认为我有什么问题?我认为我的问题是“站点状态”=>“状态值”行。=>语法是什么意思?这就是在PHP中构建关联数组的语法。你需要注销结果以查看响应是什么..我添加了一个echo curl_exec($rest),得到了错误{“error”:“unauthorized”}。确定你有正确的应用程序id和rest api密钥吗?。。错误表明情况并非如此。