HttpClient httpClient = new HttpClient();
PostMethod post = new PostMethod(url);
NameValuePair[] pairs= new NameValuePair[2];
pairs[0] = new NameValuePair("sign", "56D2D7C88561320FF7698CCE84535EAB");
pairs[1] = new NameValuePair("time", "1513232955066");
post.setRequestBody(pairs);
post.setRequestHeader("charset", "utf-8");
byte[] b = null;
try {
int status = httpClient.executeMethod(post);
if( status==200){
b = post.getResponseBody();
InputStream is = new ByteArrayInputStream(b);
byte[] decompress = ZLibUtils.decompress(is);
xml = new String(decompress);
System.out.println(xml);
}else{
System.out.println(status);
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
代码如上:有三台服务器S,A,B。A,B(服务器tomcatA,tomcatB都已设置了URIEncoding="UTF-8")部署同一个web项目,并分别向S发送请求得到返回的中文数据,结果A中文乱码,B数据正常,请问怎么回事?
A服务器环境不对。从这里来看,应该是你代码里使用了默认编码,而B的默认编码是正确的,但是A的默认编码不对。