cercando di fare l'equivalente di questo in PHP - e in mancanza :):L'invio di autenticazione nelle intestazioni PHP arricciare
curl -H "X-abc-AUTH: 123456789" http://APIserviceProvider=http://www.cnn.com;
"123456789" è la chiave API. L'istruzione della riga di comando funziona correttamente.
codice PHP (non funziona):
$urlToGet = "http://www.cnn.com";
$service_url = "http://APIserviceProvider=$urlToGet";
//header
$contentType = 'text/xml'; //probably not needed
$method = 'POST'; //probably not needed
$auth = 'X-abc-AUTH: 123456789'; //API Key
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
//does not work
// curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-type: ' .
// $contentType . '; auth=' . $auth));
//works! (THANKS @Fratyr for the clue):
curl_setopt($ch, CURLOPT_HTTPHEADER, Array($auth));
//this works too (THANKS @sergiocruz):
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Some_custom_header: 0',
'Another_custom_header: 143444,12'
));
//exec
$data = curl_exec($ch);
echo $data;
curl_close($ch);
Tutte le idee?
Perché stai usando ' Content-Type' se il tuo esempio di riga di comando ha un'intestazione 'X-abc-AUTH:'? – mario
Stavo ricevendo un errore "tipo di contenuto richiesto". Ma ho appena capito! Ho aggiornato il codice sopra. – ven