Java - Pérdida de sesión con HttpClient y GetMethod

 
Vista:

Pérdida de sesión con HttpClient y GetMethod

Publicado por Guillermo (2 intervenciones) el 04/09/2008 11:14:54
Hola estoy desarrollando una aplicación en Java que se encarga de leer el código fuente de una página y a través de ahí seguir una navegación... Lo que viene siendo el típico robot...

Vale, pues el caso es que me he encontrado con el caso de que yo llego a la página y después de leer los campos que se incluyen en el form y enviárselos me niega el acceso porque dice que "Los datos de la sesión son incorrectos"

¿Cómo hago para que se crea que se encuentra en la misma sesión?

¡Muchas gracias!

Esto que pongo, es gran parte del codigo:

NameValuePair nameValuePair[] = null;

//Establezco la primera comunicación
GetMethod getMethod = new GetMethod("https://www.XXXXXXXX.XX/XXXXXXXX/XXX/XXXXXXXXX/XXXXXX/XXXXXXContenido.jsp");
getMethod.setFollowRedirects(true);
nameValuePair = new NameValuePair[2];
nameValuePair[0] = new NameValuePair ("accesoEstadisticas", "null");
nameValuePair[1] = new NameValuePair ("TipoEstadistica", "null");
getMethod.setQueryString(nameValuePair);
httpClient.executeMethod(getMethod);
byte[] arrbytResponseBody = getMethod.getResponseBody();
String strBody = new String(arrbytResponseBody);
saveLogHTML(arrbytResponseBody, "1_PaginaLogin.html");

//Obtencion del Captcha
String rndFactor = strBody.substring(strBody.indexOf("var randomNumber = Math.round(Math.random()*"));
rndFactor = rndFactor.substring("var randomNumber = Math.round(Math.random()*".length(), rndFactor.indexOf(");"));
String gifCode = ""+Math.round(Math.random()* Long.parseLong(rndFactor));
getMethod = new GetMethod("https://www.XXXXXXXX.XX/XXXXX.XXXXXX.XXX.XXX.servlets.srvGIF");
getMethod.setFollowRedirects(true);
nameValuePair = new NameValuePair[1];
nameValuePair[0] = new NameValuePair ("code", gifCode);
getMethod.setQueryString(nameValuePair);
httpClient.executeMethod(getMethod);
arrbytResponseBody = getMethod.getResponseBody();
strBody = new String(arrbytResponseBody);
saveLogHTML(arrbytResponseBody, "2_Captcha.gif");

//Realizo OCR y envio parametros
Ocr4 ocr4 = new Ocr4();
ocr4.setWorkFile("D:\2_Captcha.gif");
String codeRead = ocr4.read();
getMethod = new GetMethod("https://www.XXXXXXXX.XX/XXXXXXXX/XXX/XXXXXXXXX/XXXXXX/XXXXXXChk.jsp");
getMethod.setFollowRedirects(true);
nameValuePair = new NameValuePair[5];
nameValuePair[0] = new NameValuePair ("usuario", "USUARIO");
nameValuePair[1] = new NameValuePair ("clave", "PASSWORD");
nameValuePair[2] = new NameValuePair ("gifcode", codeRead);
nameValuePair[3] = new NameValuePair ("TipoEstadistica", "null");
nameValuePair[4] = new NameValuePair ("linkPulsado", "1");
getMethod.setQueryString(nameValuePair);
httpClient.executeMethod(getMethod);
arrbytResponseBody = getMethod.getResponseBody();
strBody = new String(arrbytResponseBody);
saveLogHTML(arrbytResponseBody, "3_doLogin.html");
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder