这适用于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);
?>
答案 0 :(得分:4)
由于请求必须是PUT请求,请删除
curl_setopt($ch, CURLOPT_POST, true);
并使用
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");