Multiple HTTP requests using sockets in java
Posted
by
codeomnitrix
on Stack Overflow
See other posts from Stack Overflow
or by codeomnitrix
Published on 2010-12-22T14:30:57Z
Indexed on
2010/12/22
14:54 UTC
Read the original article
Hit count: 242
java
|networking
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.
© Stack Overflow or respective owner