Servus,
ich muss eine HTTP-Verbindung via Sockets manuell aufbauen, bekomme aber keine Antwort. Test-Code läuft unendlich lang (beim richtigen Code werd ich nen Timeout einbauen).
package javaapplication1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
/\*\*
\*
\* @author michi
\*/
public class Main {
/\*\*
\* @param args the command line arguments
\*/
public static void main(String[] args) {
try {
String url = "www.google.de";
Socket cS = new Socket(url, 80);
PrintWriter bos = new PrintWriter(cS.getOutputStream());
BufferedReader is = new BufferedReader(new InputStreamReader(cS.getInputStream()));
bos.write("GET /wiki/Katzen HTTP/1.1\nHost: de.wikipedia.org\n");
System.out.println("Empfang....");
String nl = is.readLine();
while (nl != "") {
System.out.println(nl);
nl = is.readLine();
}
} catch (UnknownHostException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Frage ist klar: Warum kommt keine Antwort vom Server?
grtz
michi