How to connect to multiple APIs with the same custom request header name

时间:2018-02-01 18:18:33

标签: php curl

$headers = array(
 'Custom-Key-Name:'. $apikey1,
 'Custom-Key-Name:'. $apikey2,   
 'Content-Type: application/json'
);
...
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

Something like that is what im trying to do. I can connect to 1 just fine, but there are 3 separate APIs I need to read from each with their own key, but they want you to use the same key name. When I try it like the way i've written it just reads one of them.

1 个答案:

答案 0 :(得分:0)

$headersForA = array(
 'Custom-Key-Name:'. $apikey1,
 'Content-Type: application/json'
);
...
curl_setopt($ch, CURLOPT_HTTPHEADER, $headersForA);
$responseA = curl_exec($ch);

$headersForB = array(
 'Custom-Key-Name:'. $apikey2,
 'Content-Type: application/json'
);
...
curl_setopt($ch, CURLOPT_HTTPHEADER, $headersForB);
$responseB = curl_exec($ch);

$headersForC = array(
 'Custom-Key-Name:'. $apikey3,
 'Content-Type: application/json'
);
...
curl_setopt($ch, CURLOPT_HTTPHEADER, $headersForC);
$responseC = curl_exec($ch);
相关问题