I'm trying to import and use the interface HttpRequest.BodyPublisher
import jdk.incubator.http.HttpRequest.BodyPublisher;
...
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = null;
try {
response = client.send(
HttpRequest
.newBuilder(configuration.getPostFileRequest())
.headers("Content-MD5", md5)
.POST(HttpRequest.BodyPublisher.fromFile(Paths.get(file.getPath())))
.build(),
HttpResponse.BodyHandler.asString()
);
And I got error when compiling
Error:(5, 38) java: cannot find symbol
symbol: class BodyPublisher
location: class jdk.incubator.http.HttpRequest
Error:(49, 35) java: cannot find symbol
symbol: variable BodyPublisher
How can I fix error or correct use?
module-info.java
module file.exchange.client {
requires jdk.incubator.httpclient;
requires java.logging;
}
Java version 10.0.1
Update: Compiled and ran fine when I used JDK11 and module java.net.http