3

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?

Cyrine
  • 75
  • 1
  • 1
  • 5

3 Answers3

4

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
Dmitri T
  • 119,313
  • 3
  • 56
  • 104
  • each time i see a very good simple and depth answers from you . Thank you – Suman g May 26 '16 at 05:38
  • still not working. when i add -x localhost:8888 to my curl i get a fileNotFoundException even that the file exists. ( when i execute my curl without the -x localhost:8888 it works just fine ). and the second option not working too : it returns an error telling me the body is empty even that i choose the multipart/form-data and i've put a file to upload. – Cyrine May 26 '16 at 13:14
  • It finally worked. The problem was that i must put the file to upload under jmeter/bin directory. – Cyrine May 26 '16 at 14:19
1

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.

Suman g
  • 439
  • 3
  • 12
0

For JMeter 5.1 or higher. There is an easier solution for creating test plan from curl just like in Postman

ToolsImport from curl → Paste your curl into the box → Create Test Plan

In some older version, the path can be:

HelpImport from curl → Paste your curl into the box → Create Test Plan

thangdc94
  • 1,130
  • 2
  • 19
  • 32