如何使用Java 10中的HttpRequest.BodyPublisher jdk.incubator.httpclient?

时间:2018-06-08 10:15:15

标签: java java-10

我正在尝试导入并使用界面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

编译并运行正常

0 个答案:

没有答案