java.net.http · java.net.http · since Java 11

HttpResponse

declaration
public interface HttpResponse<T>

The exchange result: statusCode(), headers(), and a body of whatever type the BodyHandler produced. Non-2xx does not throw — check the code.

Key methods

int statusCode()Check it — 404 arrives as a normal response.
T body()String, Path, InputStream, Stream<String>… per handler.
static BodyHandlers.ofString() / ofFile(Path) / ofInputStream()The standard handlers.