doushang1890 2019-06-11 20:55
浏览 673

使用cURL PHP从页面获取所有cookie

enter image description here I'm trying to access a page using PHP's cURL, this page is to return 2 cookies in the "Response Headers", but in the cURL header only returns the first one.

Does anyone know if there might be some block on the page, and how to work around this problem?

This cookie is generated on a "Status Code: 302"

I've already tried to get "file_get_contents" and also tried to do the "CURLOPT_HEADERFUNCTION" function and I also know success OBS: The function to break the google captcha is already working.

$url = 'https://pje.trt15.jus.br/captcha/login_post.php';

$post = [
        'g-recaptcha-response' => $g_response,
        'referer'              => '/consultaprocessual/pages/consultas/ConsultaProcessual.seam',
        'random'               => $g_captcha_random,
        'entrar'               => $g_captcha_entrar
    ];

    if( $g_captcha_enviar != null )
        $post[$g_captcha_enviar] = 'Enviar';

    if( $g_captcha_entrar != null )
        $post['entrar'] = $g_captcha_entrar;


    $post_http = http_build_query($post);

    $headers = [
        ':authority: pje.trt15.jus.br',
        ':method: POST',
        ':path: /captcha/login_post.php',
        ':scheme: https',
        'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
        //'accept-encoding: gzip, deflate, br',
        'accept-language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7',
        'cache-control: no-cache',
        'content-length: ' . strlen($post_http),
        'content-type: application/x-www-form-urlencoded',
        'cookie: '.$cookie_captchasess.' _ga=GA1.3.1830456077.1560269951; _gid=GA1.3.249690674.1560269951',
        'origin: https://pje.trt15.jus.br',
        'referer: https://pje.trt15.jus.br/consultaprocessual/pages/consultas/ConsultaProcessual.seam',
        'upgrade-insecure-requests: 1'
    ];

    $options = [
        CURLOPT_COOKIESESSION   => true,
        CURLOPT_HEADER          => true,
        CURLOPT_POST            => true,
        CURLOPT_POSTFIELDS      => $post_http,
        CURLOPT_HTTPHEADER      => $headers,
        CURLOPT_COOKIE          => $cookie_captchasess,
        CURLOPT_FRESH_CONNECT   => true,
        CURLOPT_VERBOSE         => true,
        CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS,
        CURLOPT_ENCODING        => 'gzip, deflate',

        CURLOPT_URL            => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_AUTOREFERER    => true,
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_TIMEOUT        => 40,
        CURLOPT_USERAGENT      => $user_agent,
    ];

    $ch = curl_init();
    curl_setopt_array($ch, $options);
    $resp = curl_exec($ch);
    curl_close($ch);

    echo "<pre>";
    echo $resp;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ogg dd trandata 报错
    • ¥15 高缺失率数据如何选择填充方式
    • ¥50 potsgresql15备份问题
    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错