In fact, you’ve been able to pass this as an array since PHP 5.2.10, so to set multiple headers in the stream context, I just used this:
[pyg language=”php”]
[
“method” => “POST”,
“header” => [“Authorization: token ” . $access_token,
“Content-Type: application/json”],
“content” => $data
]];
$context = stream_context_create($options);
[/pyg]
The $access_token
had been set elsewhere (in fact I usually put credentials in a separate file and exclude it from source control in an effort not to spread my access credentials further than I mean to!), and $data
is already encoded as JSON. For completeness, you can make the POST request like this:
[pyg language=”php”]