String resStr;
try {
String reqUrl = "";
HttpClient httpClient = new HttpClient(new HttpClientParams(),
new SimpleHttpConnectionManager());
PostMethod method = new PostMethod(reqUrl);
//设置请求的编码
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
// //设置请求报文头的编码
// method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
// method.setRequestHeader("Accept", "text/plain;charset=utf-8");
httpClient.executeMethod(method);
resStr = method.getResponseBodyAsString();
} catch (Exception ex) {
throw new BusinessException(ResultCode.FAIL);
}
需要设置请求的编码。