Answer the question
In order to leave comments, you need to log in
How to log in to the site (Java)?
Greetings forum members.
I'm writing a "parser" page, and ran into some problem. To pull the data I need, you first need to log in. I rummaged through a lot of ru / eng resources and, unfortunately, could not find a suitable solution.
The only, in my opinion, similar solution is presented below: (but it does not work either)
private static void logIn () {
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpPost httpost = new HttpPost("https://passport.ageofclones.com/index.php/");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("username", "xxxxxxx"));
nvps.add(new BasicNameValuePair("password", "yyyyyyy"));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpost, responseHandler);
System.out.println("----------------------------------------");
System.out.println(responseBody);
System.out.println("----------------------------------------");
} catch (IOException e) {
System.out.println(String.format("(login) Ошибка! — %s : %s", e.getClass().getSimpleName(), e.getMessage()));
} finally {
httpclient.getConnectionManager().shutdown();
}
}
Answer the question
In order to leave comments, you need to log in
I didn’t understand exactly what I wanted, but I would take Jsoup, google maybe this is what you need)
Just in case: POST request for authorization, after the response, save cookies somewhere, and in each next request (GET POST ...) pass cookies.
For you, like many others, the solution is to learn how to debug network applications, it's about both your application and the original page in the browser, for this you need a sniffer, there are many of them, Fiddler, Wireshark, etc., if you don't learn, you will never be able to do it fully. That's all I wanted to say.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question