public static HttpResult doJsonPost(String url, String json, String charset, boolean isGzip) throws UnsupportedEncodingException {
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new UTF8PostMethod(url);
if (isGzip) {
byte[] jsonByte = GZipUtils.compressToByte(json);
ByteArrayInputStream in = new ByteArrayInputStream(jsonByte);
postMethod.setRequestEntity(new InputStreamRequestEntity(in));
} else {
postMethod.setRequestEntity(new StringRequestEntity(json,"application/json; charset=utf-8",DEFAULT_CHARSET));
}
String res = "fail";
HttpResult hr = new HttpResult();
// 默认404
int code = 404;
try {
httpClient.executeMethod(postMethod);
// 获取二进制的byte流
if (StringUtils.isBlank(charset)) {
charset = DEFAULT_CHARSET;
}
code = postMethod.getStatusCode();
res = read(postMethod.getResponseBodyAsStream(), charset);
} catch (Exception e) {
res = "fail";
throw new SystemException("HttpRequestUtil doJsonPost方法发送post请求失败", e);
} finally {
postMethod.releaseConnection();
}
hr.setResponseCode(code);
hr.setBody(res);
return hr;
}
这段代码,用jemter怎么模拟