社区之星 2015-07-27 03:45 采纳率: 0%
浏览 3057
已结题

Jemter测试,传输byte数据到服务器问题

    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 2015-07-28 05:23
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?