Multiple HTTP requests using sockets in java
- by codeomnitrix
How could i send multiple http requests from my java program using sockets. actually i have tried as:
import java.net.*;
import java.io.*;
class htmlPageFetch{
public static void main(String[] args){
try{
Socket s = new Socket("127.0.0.1", 80);
DataInputStream dIn = new DataInputStream(s.getInputStream());
PrintWriter dOut = new PrintWriter(s.getOutputStream(), true);
dOut.println("GET /mytesting/justCheck.html HTTP/1.1\r\nHost:localhost\r\n\r\n");
boolean more_data = true;
String str;
int i = 0;
while(more_data){
str = dIn.readLine();
if(str==null){
//Now server has stopped sending data //So now write again the inputs
dOut.println("GET /mytesting/justCheck1.html HTTP/1.1\r\nHost:localhost\r\n\r\n");
continue;
}
System.out.println(str);
}
}catch(IOException e){
}
}
}
But when I send the request again it was not processed?
Thank in advance.