Pregunta

This is for GoInstant, and I can't seem to convert it to a PHP cURL request.

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

This is what I've got:

<?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);
?>  
¿Fue útil?

Solución

Since the request must be a PUT request, remove

curl_setopt($ch, CURLOPT_POST, true); 

and use

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top