Skip to content

Instantly share code, notes, and snippets.

@stopsatgreen
Last active May 31, 2019 17:55
Show Gist options
  • Save stopsatgreen/0354e3caae422c984175 to your computer and use it in GitHub Desktop.
Save stopsatgreen/0354e3caae422c984175 to your computer and use it in GitHub Desktop.
PHP: get JSON, with headers
<?php
// Because I don’t use PHP often enough to remember it instantly
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept: application/json"
)
);
$context = stream_context_create($opts);
$file = file_get_contents($url, false, $context);
$obj = json_decode($file);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment