Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testing a curl request with jmeter

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?

like image 218
Cyrine Avatar asked May 25 '16 14:05

Cyrine


People also ask

How do you test curl?

The curl package is pre-installed on most Linux distributions today. To check whether the Curl package is installed on your system, open up your console, type curl , and press enter. If you have curl installed, the system will print curl: try 'curl --help' or 'curl --manual' for more information .


2 Answers

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
like image 99
Dmitri T Avatar answered Sep 29 '22 02:09

Dmitri T


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

like image 39
thangdc94 Avatar answered Sep 29 '22 03:09

thangdc94