Untitled
unknown
plain_text
a year ago
1.5 kB
2
Indexable
Never
public int getMoreOrLess(String guess) throws IOException, InterruptedException { String json = "{\"password\": \"" + guess + "\"}"; HttpRequest.BodyPublisher body = HttpRequest.BodyPublishers.ofString(json); HttpRequest request = HttpRequest.newBuilder() .POST(body) .uri(URI.create("http://ya.praktikum.fvds.ru:8080/dev-day/task/3")) .header("AUTH_TOKEN", "e4dfc14a-9afb-4867-94d2-29351cc15431") .header("content-type", "application/json") .build(); HttpResponse.BodyHandler<String> handler = HttpResponse.BodyHandlers.ofString(); HttpResponse<String> response = client.send(request, handler); JsonElement jsonElement = JsonParser.parseString(response.body()); JsonObject jsonObject = jsonElement.getAsJsonObject(); String prompt = jsonObject.get("prompt").getAsString(); switch (prompt) { case "<pass": return -1; case ">pass": return 1; case "Хммм,а вы точно помните из каких символов состоит пароль?": return 2; default: System.out.println("Подбор завершен. " + guess); System.out.println("Код ответа: " + response.statusCode()); System.out.println("Тело ответа: " + response.body()); return 0; } }