如何使用Java 10 jdk.incubator.httpclient中的HttpRequest.BodyPublisher?
我正在尝试导入并使用接口如何使用Java 10 jdk.incubator.httpclient中的HttpRequest.BodyPublisher?,java,java-10,Java,Java 10,我正在尝试导入并使用接口HttpRequest.BodyPublisher import jdk.incubator.http.HttpRequest.BodyPublisher; ... HttpClient client = HttpClient.newHttpClient(); HttpResponse<String> response = null; try { response = client.send( HttpRequest
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()
);
如何修复错误或正确使用
module-info.java
module file.exchange.client {
requires jdk.incubator.httpclient;
requires java.logging;
}
Java版本10.0.1
更新:在我使用JDK11和模块java.net.http时编译并运行良好您可以指定您正在使用哪个IDE(intelliJ、eclipse等)或构建工具(maven、gradle等)进行编译吗?任何依赖类路径的人都必须添加
——添加模块jdk.incubator.httpclient
。旁注-这同样适用于我,使用intelliJ 2018.2 CE EAP的模块路径编译上述代码。@nullpointer我正在使用intelliJ 2018.1.4和——添加模块jdk.incubator.httpclient
添加到VM选项
module file.exchange.client {
requires jdk.incubator.httpclient;
requires java.logging;
}