配置jMeter Http请求以模拟此curl命令

时间:2017-10-13 22:22:38

标签: rest curl jmeter

我在使用curl命令在jMeter中准备HTTP Requers时遇到问题:

curl --insecure -X POST -H "Content-Type:multipart/form-data" --header 
'header-param-1: aGVhZGVyLXBhcmFtLTE=' --header 'header-param-2: aGVhZGVyLXBhcmFtLTI=' 
--header 'header-param-3: aGVhZGVyLXBhcmFtLTM=' -F "file=@C:\temp\file to upload.zip" 
--form "metadata={\"jsonParam1\": \"text1\", \"jsonParam2\": 999, \"jsonParam3\": 10222, 
\"jsonParam4\":  \"2017-10-13T23:23:02.677Z\", \"jsonParam5\": \"text5\", 
\"jsonParam6\": \"3\", \"fileName\": \"file to upload.zip\", 
\"fileType\": \"application/pdf\"};type=application/json" 
"http://localhost:7001/context/rest/v1/uploadservice"

基本上,它将文件作为multipart / form-data和json发送到正文中作为application / json类型。 curl命令按预期工作,但我不能让jMeter做同样的事情。

我试图找到合适的解决方案并最终承诺手动构建身体数据会有所帮助,但我没有运气。

我使用Cygwin进行卷曲,因为我使用的是Windows。我也试过使用postman,但也没有配置它。

请帮忙。

2 个答案:

答案 0 :(得分:1)

使用标题管理器作为子级创建HTTP请求 Test Plan

enter image description here标题管理器位于:

HTTP请求“参数”面板的配置如下:

Http Request parameters

其中包含“文件上传”面板:

enter image description here

答案 1 :(得分:1)

只记录请求。

  1. file to upload.zip复制到JMeter安装的“bin”文件夹
  2. 从JMeter的主菜单中选择`文件 - >模板 - >录制“并点击”创建“
  3. 展开WorkBench -> HTTP(S) Test Script Recorder,然后点击“开始”
  4. 运行“curl”命令,如:

    curl -x http://localhost:8888 --insecure -X POST -H ......
    
  5. JMeter将捕获您的请求并将其存储在Test Plan -> Thread Group -> Recording Controller
  6. 参考文献:

相关问题