Verifying solutions in Java

java
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Example {
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException, InterruptedException {
var mapper = new ObjectMapper();
Map<String, String> values = new HashMap<>() {{
put("secretKey", "sk_xxxxxxxx");
put("solution", "..."); // Extract the solution from the request body (_botpoison)
}};
String body = mapper.writeValueAsString(values);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.botpoison.com/verify"))
.header("accept", "application/json")
.header("content-type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
HashMap<String, Object> deserialized = mapper.readValue(response.body(), new TypeReference<Map<String, Object>>() {});
var isOk = (boolean) deserialized.get("ok");
if (isOk) {
System.out.println("Not spam: allow request");
} else {
System.out.println("Spam: reject request");
}
}
}