| 139 | } |
| 140 | |
| 141 | public static JsonObject processResult(CloseableHttpResponse httpResponse) { |
| 142 | JsonObject resultJson = null; |
| 143 | |
| 144 | if (httpResponse != null) { |
| 145 | int responseStatusCode = httpResponse.getStatusLine().getStatusCode(); |
| 146 | // 从响应对象中获取响应内容 |
| 147 | // 通过返回对象获取返回数据 |
| 148 | HttpEntity entity = httpResponse.getEntity(); |
| 149 | |
| 150 | String result = null; |
| 151 | try { |
| 152 | // 通过EntityUtils中的toString方法将结果转换为字符串 |
| 153 | result = EntityUtils.toString(entity); |
| 154 | resultJson = new Gson().fromJson(result, JsonObject.class); |
| 155 | } catch (Exception e) { |
| 156 | log.debug("HttpUtils parse json error: {}", result.substring(0, 100)); |
| 157 | } |
| 158 | } |
| 159 | return resultJson; |
| 160 | } |
| 161 | |
| 162 | private static NameValuePair getNameValuePair(Map.Entry<String, JsonElement> entry) { |
| 163 | return new BasicNameValuePair(entry.getKey(), Optional.ofNullable(entry.getValue()).map(Object::toString).orElse(null)); |