The POST request result

Report a typo

Assume you send such a JSON in a request body:

{
    "language": "Java"
}

What will be the output of that request with such the handlePostRequest() method?

public Headers handlePostRequest(HttpExchange exchange) throws IOException {
    String response = "";

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(exchange.getRequestBody()))) {
        while(reader.ready()) {
            response += reader.readLine();
        }
    }

    response = "My programming language is " + response.split(":")[1].replaceAll("[^a-zA-Z]", "");

    exchange.sendResponseHeaders(200, response.length());

    try (OutputStream stream = exchange.getResponseBody()) {
        stream.write(response.getBytes());
    }

    return exchange.getResponseHeaders();
}
Enter a short text
___

Create a free account to access the full topic