Utilizzo di Java per accedere a www.messenger.com


Ho problemi a usare il codice a cui ho trovato l'accesso www.messenger.com. Sembra che non sia capace di scrivere parametri di forma perch non ho i nomi di forma giusti. Sto avendo problemi a trovare il nome del modulo del pulsante e cosa impostarlo uguale a. Il mio obiettivo finale รจ ottenere il codice html dopo l'accesso.

Fonte: http://www.dreamincode.net/forums/blog/114/entry-2715-login-to-a-website-from-java /

import java.net.*;
import java.io.*;

private static URL URLObj;
private static URLConnection connect;

public static void main(String[] args) {
    try {
        // Establish a URL and open a connection to it. Set it to output mode.
        URLObj = new URL("http://www.messenger.com/#");
        connect = URLObj.openConnection();
        connect.setDoOutput(true);  
    }
    catch (MalformedURLException ex) {
        System.out.println("The URL specified was unable to be parsed or uses an invalid protocol. Please try again.");
        System.exit(1); 
    }
    catch (Exception ex) {
        System.out.println("An exception occurred. " + ex.getMessage());
        System.exit(1);
    }


    try {
        // Create a buffered writer to the URLConnection's output stream and write our forms parameters.
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connect.getOutputStream()));
        writer.write("email=MyEmail&pass=MyPassword&submit=Sign In");
        //writer.close();

        // Now establish a buffered reader to read the URLConnection's input stream.
        BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));

        String lineRead = "";

        // Read all available lines of data from the URL and print them to screen.
        while ((lineRead = reader.readLine()) != null) {
            System.out.println(lineRead);
        }
        reader.close();
    }
    catch (Exception ex) {
        System.out.println("There was an error reading or writing to the URL: " + ex.getMessage());
    }
}
Author: Cache Staheli, 2016-06-19

1 answers

Questi sono i parametri post, che vengono inviati da un browser, quando si fa clic su login:

default_persistent=0
email=user
initial_request_id=A2NPA_SLbM3wAkFRM_Y0fLx
lgndim=eyJ3IjoxOTIwLCJoIjoxMjAwLCJhdyI6MTkyMCwiYWgiOjExNjAsImMiOjI0fQ==
lgnjs=n
lgnrnd=125813_Br9w
login=1
lsd=AVrsF9i0
pass=pass
timezone=-120

Forse hai bisogno di alcuni di questi per ottenere un accesso di successo.

Puoi trovarli come parametri nascosti nel modulo con l'id "login_form".

 0
Author: zuim, 2016-06-19 20:02:57