URLUtils urlUtils = new URLUtils();
address = urlUtils.createURL(loginUrl, address).trim();
address = urlUtils.getCanonical(address);
referer = loginUrl.toString();
WebClient webClient = httpMethod.getWebClient();
HttpHost httpHost = webClient.createHttpHost(address);
HttpPost httpPost = webClient.createFormPostMethod(address, referer, params);
HttpResponse response2 = httpMethod.execute(httpHost, httpPost);
/*statusLine = response2.getStatusLine();
statusCode = statusLine.getStatusCode();
if(statusCode == HttpStatus.SC_MOVED_PERMANENTLY
|| statusCode == HttpStatus.SC_SEE_OTHER
|| statusCode == HttpStatus.SC_TEMPORARY_REDIRECT) {
Header header = response2.getFirstHeader("Location");
if(header != null
&& header.getValue() != null
&& !header.getValue().trim().isEmpty()) {
System.out.println(header.getValue());
try {
response2 = httpMethod.execute(header.getValue(), null);
} catch (Throwable e) {
e.printStackTrace();
}
System.out.println(" da xong roi ");
}
}*/
// System.out.println("status code "+ statusCode);
// Header [] headers = response2.getAllHeaders();
// for(Header header : headers) {
// System.out.println(header.getName() + " : " + header.getValue());
// }
byte [] bytes = new byte[0];
// org.vietspider.common.io.DataWriter writer = new org.vietspider.common.io.DataWriter();
// java.io.File file = UtilFile.getFile("track/logs/", "login_" + Utils.toFileName(address));
loginUtil.setPrevLogin(tokens);
boolean error = false;
try {
bytes = responseReader.readBody(response2);
} catch (SocketException e) {
LogService.getInstance().setMessage("WEB", e, e.toString());
bytes = e.toString().getBytes();
error = true;
} catch (Exception e) {
LogService.getInstance().setThrowable("WEB", e);
bytes = e.toString().getBytes();
error = true;
}
if(webClient.isLog()) {
java.io.File file = UtilFile.getFile("track/logs/", "login_" + Utils.toFileName(address));
LogService.getInstance().setMessage("WEB", null, "Login to: " +address);
new org.vietspider.common.io.DataWriter().save(file, bytes);
}