Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 15 su 15

Hybrid View

  1. #1
    Utente di HTML.it L'avatar di tony83
    Registrato dal
    Feb 2005
    Messaggi
    3,179
    Quote Originariamente inviata da Alex'87 Visualizza il messaggio
    Esatto.

    Fai la tua richiesta e ottieni l'html (che č quello della pagina che vedresti sul browser). Avendo l'html ti cerchi quello che ti serve interrogando il documento con Jsoup (con query XPATH).
    Trovi qualche esempio su http://jsoup.org/cookbook/extracting...dom-navigation
    invece per la login e cookie come lo devo gestire ? come faccio a mantenere lo stato sempre ?
    Tony

  2. #2
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802
    Per quello dovresti studiarti un po' il protocollo http, giusto per capire come funziona una richiesta http.
    A livello di codice ti sconsiglio di implementare tutto da capo soprattutto quando ci sono le (ottime) librerie di Apache (che non richiedono grosse conoscenze di quello che sta sotto):

    http://hc.apache.org/httpcomponents-...uickstart.html
    http://hc.apache.org/httpcomponents-.../examples.html
    http://hc.apache.org/httpcomponents-...tml/index.html

    Se guardi ci sono degli esempi anche con i cookie
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

  3. #3
    Utente di HTML.it L'avatar di tony83
    Registrato dal
    Feb 2005
    Messaggi
    3,179
    Quote Originariamente inviata da Alex'87 Visualizza il messaggio
    Per quello dovresti studiarti un po' il protocollo http, giusto per capire come funziona una richiesta http.
    A livello di codice ti sconsiglio di implementare tutto da capo soprattutto quando ci sono le (ottime) librerie di Apache (che non richiedono grosse conoscenze di quello che sta sotto):

    http://hc.apache.org/httpcomponents-...uickstart.html
    http://hc.apache.org/httpcomponents-.../examples.html
    http://hc.apache.org/httpcomponents-...tml/index.html

    Se guardi ci sono degli esempi anche con i cookie
    Grazie di tutto !
    Tony

  4. #4
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802
    Di nulla
    Se hai qualche domanda specifica chiedi pure
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

  5. #5
    Utente di HTML.it L'avatar di tony83
    Registrato dal
    Feb 2005
    Messaggi
    3,179
    Sto provando ad effettuare la connesssione http:

    codice:
    import java.io.BufferedReader;
    import java.io.DataOutputStream;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
     
    import javax.net.ssl.HttpsURLConnection;
     
    public class HttpURLConnectionExample {
     
        private final String USER_AGENT = "Mozilla/5.0";
     
        public static void main(String[] args) throws Exception {
     
            HttpURLConnectionExample http = new HttpURLConnectionExample();
     
            System.out.println("Testing 1 - Send Http GET request");
            http.sendGet();
     
            System.out.println("\nTesting 2 - Send Http POST request");
            http.sendPost();
     
        }
     
        // HTTP GET request
        private void sendGet() throws Exception {
     
            String url = "https://areaclienti3.tre.it/133/profilo.jsp";
     
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
     
            // optional default is GET
            con.setRequestMethod("GET");
     
            //add request header
            con.setRequestProperty("User-Agent", USER_AGENT);
     
            int responseCode = con.getResponseCode();
            System.out.println("\nSending 'GET' request to URL : " + url);
            System.out.println("Response Code : " + responseCode);
     
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();
     
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
     
            //print result
            System.out.println(response.toString());
     
        }
     
        // HTTP POST request
        private void sendPost() throws Exception {
     
            String url = "https://sso.tre.it/selfcare-sso/login";
            URL obj = new URL(url);
            HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
     
            //add reuqest header
            con.setRequestMethod("POST");
            con.setRequestProperty("User-Agent", USER_AGENT);
            con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
     
            String urlParameters = "username1=347123456789&password=pippo&_eventId=submit&lt=LT-36179913-9gvxufN7fMV9HbZZU7Siw2dNSMuBSB&execution=e11s1&usertype=MSISDN";    
     
            // Send post request
            con.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(con.getOutputStream());
            wr.writeBytes(urlParameters);
            wr.flush();
            wr.close();
     
            int responseCode = con.getResponseCode();
            System.out.println("\nSending 'POST' request to URL : " + url);
            System.out.println("Post parameters : " + urlParameters);
            System.out.println("Response Code : " + responseCode);
     
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();
     
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
     
            //print result
            System.out.println(response.toString());
     
        }
     
    }
    Putroppo mi restituisce:

    codice:
    Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: https://sso.tre.it/selfcare-sso/login
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
    at HttpURLConnectionExample.sendPost(HttpURLConnectionExample.java:87)
    at HttpURLConnectionExample.main(HttpURLConnectionExample.java:23)
    Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: https://sso.tre.it/selfcare-sso/login
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
    at HttpURLConnectionExample.sendPost(HttpURLConnectionExample.java:81)
    ... 1 more
    Cosa č che sbaglio ?
    Ultima modifica di LeleFT; 19-11-2013 a 10:53 Motivo: Correzione tag QUOTE con tag CODE
    Tony

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.