testing a curl request with jmeter

∥☆過路亽.° 提交于 2019-12-10 21:33:47

问题


I have a curl request and i don't know how to transform it in 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

What is the best way of doing this?


回答1:


Option 1: Record the request

In JMeter:

  1. File -> Templates -> Recording -> Create
  2. Workbench -> HTTP(S) Test Script Recorder -> Start

In console:

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

Option 2: Building Request Manually

  1. Add HTTP Request sampler and configure it as follows:

    • Server Name: localhost
    • Port Number: 8080
    • Method: POST
    • Path: /api/v1/files/Photos/logo.jpg
    • Check Use multipart/form-data for POST
    • Switch to "Files Upload" tab
    • Click "Add" and provide full path to logo.jpg file, upload as Parameter Name and image.jpg as MIME Type
  2. Add HTTP Header Manager and provide your headers names and values there


References:

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



回答2:


Simple .

  1. Create a Thread group .

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

  2. Add a HTTP Header manager add all Header entries

    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. Add a HTTP sampler

    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. Add a Listener to verify the requests

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

By the end your Jmeter script should like

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

Happy Testing . for more information http://jmeter.apache.org/usermanual/component_reference.html if it helps dont forget to click answered.



来源:https://stackoverflow.com/questions/37440639/testing-a-curl-request-with-jmeter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!