set opt CURLOPT_USERAGENT和在header字段curl php中设置useragent之间有什么区别?

时间:2018-09-18 18:01:55

标签: php php-curl

请有人帮助我了解在curl php中设置opt的区别。

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "abcxyz",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "Accept-Language: en-US,en;q=0.5",
    "Cache-Control: no-cache",
    "Connection: keep-alive",
    "Cookie: ht=7635aa7ceda60bf1",
    "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0"
  ),
));

$curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "abcxyz",
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_COOKIE => "ht=7635aa7ceda60bf1",
      CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0",
      CURLOPT_HTTPHEADER => array(
        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
        "Accept-Language: en-US,en;q=0.5",
        "Cache-Control: no-cache",
        "Connection: keep-alive"
      ),
    ));

尝试使用CURLOPT_COOKIE和CURLOPT_USERAGENT时总是出现错误。

0 个答案:

没有答案