Reputation: 773
I am attempting to send a cURL request using PHP with the following options:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://news-api.apple.com/channels/485ae91a-2212-4276-9d07-4f6a9dc82da7/articles");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'POST';
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: multipart/form-data';
$headers[] = 'Authorization: HHMAC; key={$key}; signature={$api_signature}; date={$date}';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
My problem is my variables are not showing up as their values -- like this:
Authorization: HHMAC; key={$key}; signature={$api_signature}; date={$date}
How can I fix this?
Upvotes: 1
Views: 360
Reputation: 98931
Use the double-quotes, so the variables can expand, i.e.:
$headers[] = "Authorization: HHMAC; key={$key}; signature={$api_signature}; date={$date}";
Note:
curl_setopt($ch, CURLOPT_POST, 1);
is useless, because it's included by default when you use curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
Upvotes: 1
Reputation: 17417
Change that line to use double quotes, PHP variables aren't expanded in single-quoted strings
$headers[] = "Authorization: HHMAC; key={$key}; signature={$api_signature}; date={$date}";
Upvotes: 3