0
I’m having trouble making a POST request on a website through the component Guzzle. The target site is :http://ciagri.iea.sp.gov.br/nia1/subjetiva.aspx?cod_sis=1&idioma=1
He even enters the site but no results appear. I don’t know if the problem is HOW I make the request or if it is the PARAMETERS what a step.
Would anyone know what’s wrong
Code:
<?php
use GuzzleHttp\Client;
$client = new Client();
//Padrão para as requisições
$headers = [
'headers' =>
[
'User-Agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' => 'pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4',
'Accept-Encoding' => 'gzip, deflate',
'Referer' => 'http://ciagri.iea.sp.gov.br/nia1/subjetiva.aspx?cod_sis=1&idioma=1',
'Origin' => 'http://ciagri.iea.sp.gov.br',
'Host' => 'ciagri.iea.sp.gov.br',
'Connection' => 'keep-alive'
]
];
//Parâmetros para a primeira requisição
$body = [
'body' =>
[
'cmbAno_Inicial' => '1983',
'cmbAno_Final'=>'2014',
'cmbRegiao'=>'EDR',
'chkRegiao$0'=>'on',
'chkPerg$69'=>'on',
'imgPesquisar.x'=>'67',
'imgPesquisar.y'=>'20',
'cmbTpSaida'=>'RA'
]
];
//Primeira requisição, passamos a consulta
$param = array_merge($body, $headers);
$request = $client->createRequest('POST', 'http://ciagri.iea.sp.gov.br/nia1/subjetiva.aspx?cod_sis=1&idioma=1', $param);
$retorno=$client->send($request);
$corpo=$retorno->getBody();
echo $corpo;
could you give me an example? Because in the url itself there are already parameters that are obtained by GET
– Rodolfo Oliveira
Even with these GET parameters of the URL, you are missing the ones I mentioned. Look at the source code of the query page, note that there is
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="..." />
, besides the others I’ve listed for you.– rodorgas