未设置编码导致
//调用邮件发送中心,发送邮件
CloseableHttpClient httpClient = HttpClients.createDefault();
String requestBody = null;
try{
HttpPost httpPost = new HttpPost(EmailAndSmsSendConstant.emailServiceUrl);
// 设置请求头部信息
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
httpPost.setHeader("keyId", EmailAndSmsSendConstant.keyId);
// 构建请求体参数
requestBody = createEmailBody(warnType,subject,body,emailList);
log.info("执行邮件发送,requestBody:"+requestBody);
StringEntity entity = new StringEntity(requestBody,"UTF-8"); //增加编码设置
httpPost.setEntity(entity);
CloseableHttpResponse response= httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
return true;
}else{
log.error("邮件发送失败,请求参数:"+requestBody+",响应参数:"+JacksonUtils.objectToJson(response));
return false;
}
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));
JSONObject jsonObject = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建请求内容
......
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
......
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));