English 中文(简体)
• 如何用一个阵列的形式确定http://www.l_setopt()的功能
原标题:how to fix the http header in the form of an array for the curl_setopt() function
  • 时间:2019-09-04 19:06:49
  •  标签:

I have made a program that requires a request header in the curl function, but when I run the program the following message appears: You must pass either an object or an array with the CURLOPT_HTTPHEADER argument

请帮助确定

我使用功能曲线(......)——头盔,但结果仍然不变。

$headers = array();
$headers[] =  User-Agent: Spotify-Lite/0.13.26.56 Android/25 (vivo 1719) ;
$headers[] =  Content-Type: application/x-www-form-urlencoded ;
$headers[] =  Connection: Keep-Alive ;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result   = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

警告:治疗 你必须穿过CURLOPT的物体或阵列。 HTTPHEADER 论点

最佳回答

作为一项工作,在建立您的<代码>(标题)时尝试采用阵列方法。

$headers = new stdClass;
$headers->header1 =  User-Agent: Spotify-Lite/0.13.26.56 Android/25 (vivo 1719) ;
$headers->header2 =  Content-Type: application/x-www-form-urlencoded ;
$headers->header3 =  Connection: Keep-Alive ;

我可以提出的唯一解释是array。 https://www.php.net/manual/en/class.arrayobject.php“rel=“nofollow noreferer”>ArrayObject。 应按类别分列。

问题回答
$headers = array();
$headers["Content-Type"] = "application/x-www-form-urlencoded";

//Then on curl
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);




相关问题
热门标签