Olá alguem poderia me passar um exemplo para efetuar um login e obter o conteudo de uma página com HttpClient, tenho esse exemplo aqui:
public void login(String user, String password) {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("http://www.site.com.br/Login_Async.aspx?doc=" + user+ "&pass=" + password );
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
try {
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
byte[] responseBody = method.getResponseBody();
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
method.releaseConnection();
}
}
Mas com esse exemplo mesmo eu colocando uma senha inválida me retorna o status 200 de OK.
Tenho algo implementado em PHP assim:
curl_init("http://www.site.com.br/Login_Async.aspx?doc=00811710000100&pass=smcmt29&");
$ch = curl_init("http://www.site.com.br/Login_Async.aspx?doc=[telefone removido]&pass=senha");
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$data1 .= curl_exec($ch);
echo "resultado ".$data1;
Basicamente, preciso fazer um login e navegar pelos conteúdos das páginas que são paginadas, onde posso achar exemplos interessantes?
Grato, Fabio Pedrosa.
