R
Roland
Hello. Look on my code, which can get WWW pages: (for example
http://whatismyip.com/)
InetSocketAddress socketAddress = new InetSocketAddress(new
URL("http://whatismyip.com/").getHost(), 80);
Socket socket = new Socket();
socket.connect(socketAddress);
BufferedWriter writer = new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream()));
String request = "GET / HTTP/1.1\r\nUser-Agent: Opera/9.20
(Windows NT 5.0; U; pl)\r\nHost: whatismyip.com\r\n\r\n";
writer.write(request);
writer.flush();
StringBuffer content = new StringBuffer();
String line;
BufferedReader reader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
while ((line = reader.readLine ()) != null)
content.append(line).append ("\n");
String response = content.toString();
System.out.println(response);
Unfortunately, there is a error:
java.net.SocketException: Connection reset
in this line:
while ((line = reader.readLine()) != null)
When I download others pages, everything is OK, but this code always
cannot get http://whatismyip.com/ page. Why?
Where is an error?
Thanks for your answer.
http://whatismyip.com/)
InetSocketAddress socketAddress = new InetSocketAddress(new
URL("http://whatismyip.com/").getHost(), 80);
Socket socket = new Socket();
socket.connect(socketAddress);
BufferedWriter writer = new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream()));
String request = "GET / HTTP/1.1\r\nUser-Agent: Opera/9.20
(Windows NT 5.0; U; pl)\r\nHost: whatismyip.com\r\n\r\n";
writer.write(request);
writer.flush();
StringBuffer content = new StringBuffer();
String line;
BufferedReader reader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
while ((line = reader.readLine ()) != null)
content.append(line).append ("\n");
String response = content.toString();
System.out.println(response);
Unfortunately, there is a error:
java.net.SocketException: Connection reset
in this line:
while ((line = reader.readLine()) != null)
When I download others pages, everything is OK, but this code always
cannot get http://whatismyip.com/ page. Why?
Where is an error?
Thanks for your answer.