I am trying to experiment with Java 9's HttpClient
.
The basic example as in HttpRequest's javadoc works without problems:
HttpResponse response = HttpRequest.create(new URI("http://stackoverflow.com/"))
.version(java.net.http.HttpClient.Version.HTTP_2)
.followRedirects(HttpClient.Redirect.ALWAYS)
.GET()
.response();
int statusCode = response.statusCode();
String responseBody = response.body(HttpResponse.asString());
System.out.println("statusCode = " + statusCode);
System.out.println("responseBody = " + responseBody);
However, when trying to use sendAsyncMulti
, it does not work. No files are created in E:\foo
, the println
after join
is not reached, there is also no exception, although I basically copied the example from HttpResponse.multiFile
's Javadoc. I expected that some HTTP responses will be saved in that directory. I also tried to remove the HTTP2 and followRedirects, other URLs like google etc, but it did not change anything. What am I doing wrong?
CompletableFuture<Map<URI,Path>> cf =
HttpRequest.create(new URI("http://stackoverflow.com/"))
.version(java.net.http.HttpClient.Version.HTTP_2)
.followRedirects(HttpClient.Redirect.ALWAYS)
.GET()
.multiResponseAsync(HttpResponse.multiFile(Paths.get("E:\\foo")));
Map<URI,Path> results = cf.join();
System.out.println("after join");
If it is relevant, this is the version I am using (latest version of JDK 9):
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+126)
Java HotSpot(TM) Server VM (build 9-ea+126, mixed mode)