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

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 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题