2 laoziyaonitian laoziyaonitian 于 2015.07.27 11:45 提问

Jemter测试,传输byte数据到服务器问题 10C
    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怎么模拟

1个回答

oyljerry
oyljerry   Ds   Rxr 2015.07.28 13:23

JMeter有提供一个plugin来控制http raw requst
http://jmeter-plugins.org/wiki/RawRequest/

Csdn user default icon
上传中...
上传图片
插入图片