We're using Commission Junction's REST service, which requires we sent an API key in the Authorization
header.
We set the header like this:
$ch = curl_init();
curl_setopt_array($ch, array(
// set url, timeouts, encoding headers etc.
CURLOPT_URL => 'https://....',
// ...
));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: ' . CJ_API_KEY,
'User-Agent: ' . OUR_USER_AGENT
));
$response = curl_exec($ch);
$info = curl_getinfo($ch);
The problem is that the Authorization
header isn't sent (we debugged this by using a local url and doing a var_export($_SERVER)
which shows a User-Agent
header is set, but not the Authorization
header.)
If we change the header name to X-Authorization
, it gets sent - but this hasn't helped us as the service specifically requires the Authorization
header.
How do we get PHP + cURL to send an arbitrary Authorization
header?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…