如何将自定义标头传递给cURL?

时间:2018-10-19 14:50:16

标签: php curl header

对不起,我的英语。告诉我如何在cURL中传递非标准标头

$headers = array("Accept: application/json, text/plain, /*", 
        "Captcha: NDRMR9",
        "Referer: https://avtokod.mos.ru/AutoHistory/");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://avtokod.mos.ru/AutoHistory/GetByLicensePlate");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('licensePlate' => $licensePlate, 'sts' => $sts)));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:61.0) Gecko/20100101 Firefox/61.0');
    curl_setopt($ch, CURLOPT_COOKIEFILE, $_SERVER["DOCUMENT_ROOT"]."/cookie.txt");
    curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER["DOCUMENT_ROOT"]."/cookie.txt");
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    echo "<pre>";
    echo $response;
    print_r($info['request_header']);

但是我得到一个错误

  

{“代码”:1,“消息”:“Необходимоввестикапчу”}

I。 e。我没有发送验证码。

我看到在调试器中,Captcha参数在标头中传递

open image

我在做什么错了?

0 个答案:

没有答案