Answer the question
In order to leave comments, you need to log in
How can I get headers in this script as an array?
Tell me how can I get all the headers in the form of an array in this script?
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.apache.http.client.fluent.Async;
import org.apache.http.client.fluent.Content;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.concurrent.FutureCallback;
/**
* Java mass loader
*/
public class MassLoader {
/**
* Main method
*
* @param args
*/
public static void main(String[] args) {
URIBuilder builder = new URIBuilder();
builder.setScheme("http").setHost("google.com").setPath("/");
URI requestURL = null;
try {
requestURL = builder.build();
} catch (URISyntaxException use) {}
ExecutorService threadpool = Executors.newFixedThreadPool(100);
Async async = Async.newInstance().use(threadpool);
final Request request = Request.Get(requestURL);
for(int i=0; i < 100; i++) {
Future<Content> future = async.execute(request, new FutureCallback<Content>() {
public void failed (final Exception e) {
System.out.println(e.getMessage() +": "+ request);
}
public void completed (final Content content) {
System.out.println("Request completed: "+ request);
System.out.println("Response:\n"+ content.asString());
}
public void cancelled () {
System.out.print("Cancelled");
}
});
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question