这适用于GoInstant,我似乎无法将其转换为PHP cURL请求.
curl -X PUT \
-H 'Authorization: Bearer $ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{ "value": { "type": "hot dog", "topping": "mustard" }, "options": { "expire": 15, "cascade": "relish" } }' \
https://api.goinstant.net/v1/keys/1/1/food/1
这就是我所拥有的:
<?PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.goinstant.net/v1/keys/1/1/food/1");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('value' => array('foo' => 'hello!'))));
$stuff = curl_exec($ch, true);
echo $stuff;
curl_close($ch);
?>
解决方法:
由于请求必须是PUT请求,请删除
curl_setopt($ch, CURLOPT_POST, true);
并使用
curl_setopt($ch, CURLOPT_CUSTomrEQUEST, "PUT");