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

步骤

  1. 将proto文件转换为二进制文件
        private static AiQiYV215Rta.RTARequest_2_0 request_2_0;
    
        static {
            request_2_0 = AiQiYV215Rta.RTARequest_2_0.newBuilder()
                    .setOaid("7b6798e89994056e89c1797e6a52700c")
                    .setImeiMd5("868619039737877")
                    .setOpenUdid("ba9680df551f6de824d5aa2e61d97e5b")
                    .setIdfaMd5("868619039737878")
                    .setPlatform(32)
                    .addAdvertiserIds(1245125L)
                    .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. 单元测试

你可能感兴趣的:(问题,jmeter,java,开发语言,protobuf)