Skip to content

Instantly share code, notes, and snippets.

@duan-li
Created July 5, 2015 23:42
Show Gist options
  • Save duan-li/8b1e538d8c2ea59157b4 to your computer and use it in GitHub Desktop.
Save duan-li/8b1e538d8c2ea59157b4 to your computer and use it in GitHub Desktop.
send get request with header. Without curl
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Content-Type: application/json\r\n" .
"X-User-Email: someone@email.com\r\n" .
"X-Auth-Token: some_auth_token\r\n"
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents('https://your_api_address.com', false, $context);
if($file == false)
{
http_response_code (404);
}
else
{
http_response_code (200);
}
die;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment