php5

Use Multiple Headers in a PHP

With PHP, you can send multiple HTTP headers with file_get_contents() . you can also send information such as HTTP_ACCEPT, HTTP_ACCEPT_LANGUAGE, and HTTP_CONNECTION with file_get_contents(). In this post, I have write a complete example code to set multiple headers; an Authorization header and a Content-Type header using PHP and make POST request using file_get_contents().

<?php
$options = ["http" => [
"method" => "POST",
"header" => ["Authorization: token " . $access_token,
"Content-Type: application/json"],
"content" => $data
]];
$context = stream_context_create($options);
?>

Now using $context, you can make the POST request like this:

<?php
$response = file_get_contents($url, false, $context);
?>

Related Posts


Leave a Reply

Your email address will not be published. Required fields are marked *


*