日期:2014-05-20 浏览次数:20816 次
public static String requestToProxy(HttpEntity entity, String proxy)
throws IOException {
String serverJsonStr = null;
final HttpPost post = new HttpPost(proxy);
// 添加gzip的包头
post.addHeader("Accept-Encoding", "gzip");
post.setEntity(entity);
HttpResponse httpResponse = MjUtil.getHttpClient().execute(post);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
entity = httpResponse.getEntity();
if (entity.getContentEncoding() != null
&& entity.getContentEncoding().getValue() != null
&& entity.getContentEncoding().getValue().contains("gzip")) {
serverJsonStr = MjUtil.guzipCompress(entity.getContent());
} else {
serverJsonStr = EntityUtils.toString(entity);
}
}
return serverJsonStr;
}