I have laboratory work to make a crawler using BSD socket api, so i need to make multiple http requests to extract all responses, i was trying to do it with single socket connection, but i can get the response only after sending first request header, for other response is empty. Here is my code, so what are the solutions?:
Socket socket = new Socket("fucking-great-advice.ru", 80);
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter output = new PrintWriter(socket.getOutputStream());
for (int numberAdvice = 1; numberAdvice < 100; numberAdvice++) {
output.write("GET /advice/" + numberAdvice + " HTTP/1.0\r\n\r\n");
output.flush();
StringBuilder sb = new StringBuilder();
int ch = 0;
while ((ch = input.read()) != -1) {
sb.append((char) ch);
}
String response = sb.toString().split("\r\n\r\n")[1];
System.out.println(response);
}
input.close();
output.close();
socket.close();