HttpsURLConnection Abwürgen aus, wenn getInputStream() aufgerufen wird

[Java 1.5; Eclipse Galileo]

HttpsURLConnection scheint zu hängen, wenn die getInputStream () - Methode aufgerufen wird. Ich habe versucht, mit verschiedenen Webseiten, ohne Erfolg (derzeit https://www.google.com). Ich sollte erwähnen, ich bin über httpS.

Den code unten geändert wurde, basierend auf was ich gelernt habe von anderen StackOverflow Antworten. Jedoch keine Lösungen, die ich ausprobiert habe bisher gearbeitet haben.

Wäre ich sehr dankbar für einen Schubs in die richtige Richtung 🙂

public static void request( URL url, String query ) 
{
try{

    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

    //connection.setReadTimeout( 5000 ); //<-- uncommenting this line at least allows a timeout error to be thrown

    connection.setDoInput(true); 
    connection.setDoOutput(true);
    connection.setUseCaches(false);  
    System.setProperty("http.keepAlive", "false");


    connection.setRequestMethod( "POST" );


    //setting headers
    connection.setRequestProperty("Content-length",String.valueOf (query.length()));
    connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); //WAS application/x-www- form-urlencoded
    connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)");

    ////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////
    System.out.println( "THIS line stalls" + connection.getInputStream() );
    ////////////////////////////////////////////////////////////////////////////////////

}catch( Exception e ) {
    System.out.println( e ); 
    e.printStackTrace(); 
}

Typische Fehler wie folgt Aussehen:

java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:782)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:739)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
at java.io.BufferedInputStream.read(BufferedInputStream.java:313)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:681)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:626)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:983)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at https_understanding.HTTPSRequest.request(HTTPSRequest.java:60)
at https_understanding.Main.main(Main.java:17)
  • Nur ein Stich in der Dunkelheit, die Sie senden eine POST-Anforderung, so würde ich davon ausgehen, dass das andere Ende (google) wartet auf Sie senden einige Parameter. Alles, was Sie senden ist einige HTTP-Header. Was passiert, wenn Sie ändern Sie die POST, um eine zu BEKOMMEN?
  • Was sind Sie /wirklich/ zu tun versuchen? Ihre gmail-tag führt mich zu vermuten, Sie könnten besser mit POP -, IMAP-oder SMTP (oder eine Google custom APIs)
InformationsquelleAutor geraldalewis | 2010-02-17
Schreibe einen Kommentar