Error:(226, 34) java: cannot find symbol symbol: variable BodyPublisher location: class jdk.incubator.http.HttpRequest
private static JSONObject sendRequest(JSONObject json) throws Exception {
HttpClient client;
InetSocketAddress proxy = getRandomProxy();
if(proxy == null) {
client = HttpClient.newHttpClient();
} else {
client = HttpClient.newBuilder().proxy(ProxySelector.of(proxy)).build();
}
HttpRequest httpRequest = HttpRequest
.newBuilder(new URI(BASE_URL))
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.timeout(TIMEOUT_DURATION)
.POST(HttpRequest.BodyPublisher.fromString(json.toString()))
.build();
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandler.asString());
String jsonResponse = httpResponse.body();
return new JSONObject(jsonResponse);
}
module-info.java:
module MyProject {
requires jdk.incubator.httpclient;
}
I've tried it with OpenJDK 10 and Oracle JDK 10 on Linux.