forked from kevin.shehu/GGD
ADD : NEW Format for all the code with prettier
This commit is contained in:
@@ -9,26 +9,33 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class HttpPost {
|
||||
public String HttpCallPost(String baseUrl, String body) throws Exception {
|
||||
|
||||
var client = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||
.build();
|
||||
HttpRequest request = null;
|
||||
try {
|
||||
request = HttpRequest.newBuilder(new URI(baseUrl))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.setHeader("Content-Type", "application/json")
|
||||
.setHeader("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
CompletableFuture<HttpResponse<String>> response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString());
|
||||
String result = response.thenApply(HttpResponse::body).get(5, TimeUnit.SECONDS);
|
||||
return result;
|
||||
public String HttpCallPost(String baseUrl, String body) throws Exception {
|
||||
var client = HttpClient
|
||||
.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||
.build();
|
||||
HttpRequest request = null;
|
||||
try {
|
||||
request =
|
||||
HttpRequest
|
||||
.newBuilder(new URI(baseUrl))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.setHeader("Content-Type", "application/json")
|
||||
.setHeader("Accept", "application/json")
|
||||
.build();
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
CompletableFuture<HttpResponse<String>> response = client.sendAsync(
|
||||
request,
|
||||
HttpResponse.BodyHandlers.ofString()
|
||||
);
|
||||
String result = response
|
||||
.thenApply(HttpResponse::body)
|
||||
.get(5, TimeUnit.SECONDS);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user