vendredi 22 mai 2015

POST call fails (file_get_contents warning?) PHP

I want to make a post call with the following code:

function addWorkout() {
// url for workouts
$url = "http://ift.tt/1Ak0EOk";

// set data to send
$data = http_build_query(array(
    'time_created' => intval($_GET['starttime']),
    'time_completed' => intval($_GET['endtime']),
    'sub_type' => intval($_GET['sport']),
    'calories' => intval($_GET['calories']),
));

var_dump($data);

$options = array(
    'http' => array(
        "header" => "Content-Type: Authorization: Bearer {$_COOKIE['access_token']}\r\n",
        'method' => 'POST',
        'content' => $data
    ),
);

var_dump($options);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);

var_dump($result);

}

However it doesn't successfully make the post call. The following message appears: Warning

Warning: file_get_contents(https://...@me/workouts): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\wamp\www\FitnessWebApp\.idea\html\sport.php on line 90
Call Stack
#   Time    Memory  Function    Location
1   0.0006  280568  {main}( )   ..\sport.php:0
2   1.2201  293408  addWorkout( )   ..\sport.php:19
3   1.2204  296272  file_get_contents ( )   ..\sport.php:90

API documentation shows the following example:

POST http://ift.tt/1Ak0EOk HTTP/1.1
Host: jawbone.com
time_created=1368652731&time_completed=1368656325&sub_type=3&calories=115




Aucun commentaire:

Enregistrer un commentaire