| | |
| | | httpMethod.setRequestEntity(entity); |
| | | |
| | | int resultCode = httpClient.executeMethod(httpMethod); |
| | | // 获取响应头的字符编码 |
| | | String contentType = httpMethod.getResponseHeader("Content-Type") == null ? |
| | | null : httpMethod.getResponseHeader("Content-Type").getValue(); |
| | | String charset = "UTF-8"; // 默认使用UTF-8 |
| | | |
| | | if (contentType != null && contentType.contains("charset=")) { |
| | | String[] parts = contentType.split("charset="); |
| | | if (parts.length > 1) { |
| | | charset = parts[1].split(";")[0].trim(); |
| | | } |
| | | } |
| | | |
| | | InputStream inputStream = httpMethod.getResponseBodyAsStream(); |
| | | if (inputStream == null) { |
| | | throw new HttpRequestException(RESPONSE_NULL_ERROR_CODE, "响应为null"); |
| | | } |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,charset)); |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | String str = ""; |
| | | while ((str = reader.readLine()) != null) { |