| 125 | |
| 126 | // Tries to read the body. |
| 127 | private String readBody() { |
| 128 | // Get the connection |
| 129 | HttpURLConnection connection = getRequest().getConnection(); |
| 130 | |
| 131 | // Try to get the input stream |
| 132 | InputStream inputStream = null; |
| 133 | try { |
| 134 | inputStream = connection.getInputStream(); |
| 135 | } catch (IOException e) { |
| 136 | inputStream = connection.getErrorStream(); |
| 137 | } |
| 138 | |
| 139 | // Try to parse the input stream |
| 140 | try { |
| 141 | InputStreamReader inputStreamReader = new InputStreamReader(inputStream); |
| 142 | BufferedReader bufferedReader = new BufferedReader(inputStreamReader); |
| 143 | StringBuffer body = new StringBuffer(); |
| 144 | String inputLine; |
| 145 | while ((inputLine = bufferedReader.readLine()) != null) { |
| 146 | body.append(inputLine); |
| 147 | } |
| 148 | bufferedReader.close(); |
| 149 | // Return the response body |
| 150 | return body.toString(); |
| 151 | } catch (IOException e) { |
| 152 | // return null if we could not parse the input stream |
| 153 | return null; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // Ties to parse the response body into a JSON Object |
| 158 | private JsonObject parseJson() { |