Estou recebendo o seguinte codigo ao tentar cadastrar um abrigo: {"timestamp":"2024-01-15T19:01:41.261+00:00","status":400,"error":"Bad Request","path":"/abrigos"}
Código:
public static HttpResponse<String> dispararRequisicaoGet(String uri) throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(uri))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
return client.send(request, HttpResponse.BodyHandlers.ofString());
}
public static HttpResponse<String> dispararRequisicaoPost(String uri, Object object) throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(uri))
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(new Gson().toJson(object)))
.build();
return client.send(request, HttpResponse.BodyHandlers.ofString());
}
}