No body in JsonUrlReader for GET method
This commit is contained in:
1 parent
21e97e480c
commit
b302cf5276
1 file changed
+14
-9
+14
-9
@@ -72,16 +72,21 @@ public final class JsonUrlReader {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
HttpClient client = HttpClient.newHttpClient();
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder().uri(uri);
|
||||||
.uri(uri)
|
if (method != "GET") {
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
// FIXME: If this function is ever used to post json bodies this header
|
||||||
.method(method,
|
// will need to be configurable
|
||||||
HttpRequest.BodyPublishers.ofString(body == null ? "" : body, StandardCharsets.UTF_8))
|
requestBuilder.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
||||||
.build();
|
.method(method, HttpRequest.BodyPublishers.ofString(body == null ? "" : body,
|
||||||
|
StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
requestBuilder.GET();
|
||||||
|
}
|
||||||
|
|
||||||
// Asynchronous, non-blocking send, so that java servlet not blocked by outbound connection
|
// Asynchronous, non-blocking send, so that tomcat servlets are not blocked by outbound connection
|
||||||
CompletableFuture<HttpResponse<String>> future =
|
CompletableFuture<HttpResponse<String>> future = client.sendAsync(requestBuilder.build(),
|
||||||
client.sendAsync(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
|
HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
HttpResponse<String> response = future.join();
|
HttpResponse<String> response = future.join();
|
||||||
int status = response.statusCode();
|
int status = response.statusCode();
|
||||||
|
|||||||
Reference in new issue
Block a user