我正在尝试导入并使用界面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()
);
编译时出错
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
如何修正错误或正确使用?
module-info.java
module file.exchange.client {
requires jdk.incubator.httpclient;
requires java.logging;
}
Java版本10.0.1
更新:当我使用JDK11和模块java.net.http
编译并运行正常