cURL PHP - Retrieving page html

1

Hello,

I'm training this cURL. Can you tell me why the following snippet does not work?

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <?php
    $cURL = curl_init('http://fiesselecaoaluno.mec.gov.br/consulta/curso');
    curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
    $dados = array(
        'opcaoProcurar' => 'I',
        'noIes' => '10',
    );
    curl_setopt($cURL, CURLOPT_POST, true);
    curl_setopt($cURL, CURLOPT_POSTFIELDS, $dados);
    curl_setopt($cURL, CURLOPT_REFERER, 'http://fiesselecaoaluno.mec.gov.br/consulta/curso');
    $resultado = curl_exec($cURL);
    curl_close($cURL);
    echo $resultado;
    ?>
</body>

I wanted to get the html with cURL, but only dps of it have filled out the form correctly. Any tips?

Is it something to do with the page form, or is it because it is ajax and curl does not work for this?

    
asked by anonymous 21.02.2017 / 20:21

1 answer

0

The service you are doing post is wrong, it should be http://fiesselecaoaluno.mec.gov.br/consulta/consulta :

$cURL = curl_init('http://fiesselecaoaluno.mec.gov.br/consulta/consulta');
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
$dados = array(
    'opcaoProcurar' => 'I',
    'noIes' => '10',
);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $dados);
curl_setopt($cURL, CURLOPT_REFERER, 'http://fiesselecaoaluno.mec.gov.br/consulta/curso');
$resultado = curl_exec($cURL);
curl_close($cURL);
echo $resultado;

In this case, you can see which service is going to be done post by the form action

    
21.02.2017 / 22:18