Last active
September 29, 2016 18:09
-
-
Save isaacpompa/d1dbba6f080ec24ce5aad91478143340 to your computer and use it in GitHub Desktop.
View the API response body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private String getBodyResponse(HttpURLConnection connection){ | |
| String line = null; | |
| BufferedReader br = null; | |
| StringBuilder sb = null; | |
| String body = null; | |
| int response_code; | |
| InputStreamReader isr; | |
| try { | |
| if (connection != null){ | |
| response_code = connection.getResponseCode(); | |
| isr = (response_code == 200 || response_code == 204) ? new InputStreamReader(connection.getInputStream()) : | |
| new InputStreamReader(connection.getErrorStream()); | |
| br = new BufferedReader(isr); | |
| sb = new StringBuilder(); | |
| while ( (line = br.readLine()) != null) { | |
| sb.append(line); | |
| } | |
| body = sb != null ? sb.toString() : null; | |
| } else { | |
| System.out.println("getBodyResponse [ERROR]: No HttpURLConnection provided" ); | |
| body = null; | |
| } | |
| } catch (Exception ex) { | |
| System.out.println("getBodyResponse [EXEPTION] " + ex); | |
| } | |
| return body; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment