Print the request header

Report a typo

What do you need to write instead of the underscores to print the Accept-encoding header value?

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 = "Hello, " + response.split(":")[1].replaceAll("[^a-zA-Z]", "");

    System.out.println("Accept encoding: " + ______"Accept-encoding"));

    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