How to get response body using HttpURLConnection, when code other than 2xx is returned? December 15, 2022 by Tarik If the response code isn’t 200 or 2xx, use getErrorStream() instead of getInputStream().