PHP call REST api

<?php 

$opts = array(
		'http'=>array(
				'method'=>"GET",
				'header'=>"password: mypassword\r\n" .
				"Accept-language: en\r\n"
		)
);
	
$context = stream_context_create($opts);

$response = file_get_contents('my/api/url', false, $context);
	
$results = json_decode($response);

echo "<pre>";
print_r($results);
echo "</pre>";

?>

 

ref: – php.net

Author: bm on June 15, 2016
Category: php

One thought on “PHP call REST api