我需要对正文中包含UTF-8 JSON的服务器执行POST请求:
public HttpRequest createRequest() {
HttpPost req = new HttpPost(API_URL);
StringEntity stringEntity = new StringEntity(notification.toString(), Charset.forName("UTF-8"));
stringEntity.setContentType(ContentType.APPLICATION_JSON.toString());
req.setEntity(stringEntity);
return req;
}
stringEntity的内容类型和字符集是否自动添加到请求中?
或者我是否必须将标头添加到req
?
req.addHeader("Content-Type", "application/json; charset=UTF-8");