使用 jmeter 测试 curl 请求

testing a curl request with jmeter

我有一个 curl 请求,但我不知道如何在 jmeter 中转换它:

curl -H application-id:my-app-id -H secret-key:my-secret-key -H Content-Type:"multipart/form-data" -H application-type:REST --form upload =@/logo.jpg -X POST -v http://localhost:8080/api/v1/files/Photos/logo.jpg

最好的方法是什么?

简单 .

  1. 创建线程组。

    RightClick on TestPlan --> Threads-->Thread Group

  2. 添加 HTTP Header 管理器添加所有 Header 条目

    Right Click on Thread Group Created in Step1 --> Add-->ConfigElement-->HTTP Header Manager and add all[ -H application-id:my-app-id -H secret-key:my-secret-key -H Content-Type:"multipart/form-data" -H application-type:REST] Note: here you dont have to append -H

  3. 添加 HTTP 采样器

    Right Click on the ThreadGroup Created in Step1 --> Add-->Sampler-->HTTP Sampler provide ServerName or IP = local host and Port= 8080 and in Path =/api/v1/files/Photos/logo.jpg and method = post and There is add section for send files add accordingly

  4. 添加一个监听器来验证请求

    Right Click on ThreadGroup created in Step1 --> Add-->Listener--> View result tree

到最后你的 Jmeter 脚本应该

TestPlan
  ThreadGroup[threads =1 loopcount=1]
    HTTP HeaderManager
    HTTPSAmpler
    View Result Tree

测试愉快。了解更多信息 http://jmeter.apache.org/usermanual/component_reference.html 如果有帮助,请不要忘记点击回答。

选项 1:记录请求

在 JMeter 中:

  1. 文件 -> 模板 -> 录制 -> 创建
  2. Workbench -> HTTP(S) 测试脚本记录器 -> 开始

在控制台中:

 curl -x localhost:8888 -H application-id:my-app-id ......

选项 2:手动构建请求

  1. 添加HTTP Request采样器,配置如下:

    • 服务器名称:localhost
    • 端口号:8080
    • 方法:POST
    • 路径:/api/v1/files/Photos/logo.jpg
    • 检查 Use multipart/form-data POST
    • 切换到 "Files Upload" 选项卡
    • 单击 "Add" 并提供 logo.jpg 文件的完整路径,upload 作为参数名称,image.jpg 作为 MIME 类型
  2. 添加 HTTP Header Manager 并在那里提供您的 headers 名称和值


参考文献:

  1. curl man page
  2. JMeter Proxy Step by Step
  3. How to Save ‘Loads’ of Time Using JMeter's Template Feature

对于 JMeter 5.1 或更高版本。 从 curl 创建测试计划有一个更简单的解决方案,就像在 Postman

中一样

ToolsImport from curl → 将卷曲粘贴到框中 → Create Test Plan

在一些旧版本中,路径可以是:

HelpImport from curl → 将卷曲粘贴到框中 → Create Test Plan