-1
私のコードを持つ配列:ますcurl_setopt():あなたは、どちらか合格しなければならないオブジェクトまたはCURLOPT_HTTPHEADER引数
private static $API_ACCESS_KEY = 'AIzaSyDG3fYAj1uW7VB-wejaMJyJXiO5JagAsYI';
$headers = array(
'Authorization: key=' .self::$API_ACCESS_KEY,
'Content-Type: application/json');
private function useCurl(&$model, $url, $headers, $fields = null) {
// Open connection
$ch = curl_init();
if ($url) {
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if ($fields) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
}
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
return $result;
}
}
がエラー:
curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER argument
print_r($ headers);を使用して '$ headers'の値を出力し、コメント内にprint文の出力を追加して質問を明確にしてください。 – Daenarys
$ヘッダ=配列( \t \t '認証:キー=' .self :: $のAPI_ACCESS_KEY、 \t \t 'コンテンツタイプ:アプリケーション/ JSON' \t)。 \t \t \t print_r($ headers); Answer:Array([0] => Authorization:key = AIzaSyDG3fYAj1uW7VB-wejaMJyJXiO5JagAsYI [1] =>コンテンツタイプ:application/json) – Vinupriya