2025年怎么使用jmeter请求protobuf参数接口

怎么使用jmeter请求protobuf参数接口步骤 将 proto 文件转换为二进制文件 private static AiQiYV215Rta RTARequest 2 0 request 2 0 static request 2 0 AiQiYV215Rta RTARequest 2 0 newBuilder setOaid

大家好,我是讯享网,很高兴认识大家。

步骤

  1. 将proto文件转换为二进制文件
     private static AiQiYV215Rta.RTARequest_2_0 request_2_0; static { 
          request_2_0 = AiQiYV215Rta.RTARequest_2_0.newBuilder() .setOaid("7b6798ee89c1797e6a52700c") .setImeiMd5("7877") .setOpenUdid("ba9680df551f6de824d5aa2e61d97e5b") .setIdfaMd5("7878") .setPlatform(32) .addAdvertiserIds(L) .build(); } public static void main(String[] args) { 
          FileUtil.writeBytes(request_2_0.toByteArray(), "D:\\test\\rta\\AiQiYV215Rta.pb"); } 

    讯享网
  2. 在jmeter中创建http请求

    讯享网
  3. 使用文件上传,上传刚生成的二进制文件
  4. 添加HTTP Header Manager,配置请求头:application/x-protobuf
  5. 添加View Results Tree执行,则可以看到响应数据

问题

  1. 响应结果乱码

    讯享网@PostMapping(value = "/aiqiyi/rta", name = "爱奇艺曝光", consumes = "application/x-protobuf") public void aiQiYiTo(HttpServletRequest request, HttpServletResponse response) { 
          String logBy = this.getClass().getName() + ".aiQiYiTo:{}"; try (InputStream input = request.getInputStream(); OutputStream out = response.getOutputStream()) { 
          AiQiYV215Rta.RTARequest_2_0 aiqiyRequest = AiQiYV215Rta.RTARequest_2_0.parseFrom(input); AiQiYV215Rta.RTAResponse_2_0.Builder aiqiyResponse = AiQiYV215Rta.RTAResponse_2_0.newBuilder(); List<Long> list = aiqiyRequest.getAdvertiserIdsList(); for (Long l : list) { 
          AiQiYV215Rta.ResultList_2_0 resultList = AiQiYV215Rta.ResultList_2_0.newBuilder() .setAdvertiserId(l) .setIsDeliver(true) .build(); aiqiyResponse.addResult(resultList); } log.info(logBy, aiqiyResponse.toString()); // 此处先toString再getBytes并设置编码,不然响应结果会乱码 out.write(aiqiyResponse.toString().getBytes(StandardCharsets.UTF_8)); out.flush(); } catch (Exception exception) { 
          log.error(logBy, exception); } } 

代码

  1. 接口地址
  2. proto文件
  3. 单元测试
小讯
上一篇 2025-02-26 23:52
下一篇 2025-01-06 12:46

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/57052.html