In this blog post, we are going to see about CURL tips for performance engineers. I have already published a YouTube video about cURL for Performance Engineers. We are going to see a few more tips about cURL.
Headers to cURL
If you want to convert the headers to cURL command, there are a couple of ways you can do it.
- Clone this repository https://github.com/curl/h2c
- Launch WSL for Windows terminal.
- Store your headers in a file, e.g. example.com
GET / HTTP/1.1
Host: example.com
Then, issue the command ./h2c < example.com
. Here is the output you will get:
curl --http1.1 --header Accept: --header User-Agent: https://example.com/
If you prefer the online version, you can check this URL https://curl.se/h2c/
The online version will send your crunched data and converted on the curl server.
If you want to see more options for ./h2c, issue ./h2c -h
command.
h2c.pl [options] < file
-a Allow curl's default headers
-d Output man page HTML links after command line
-h Show short help
-H Output HTTP generated URLs instead
-i Ignore HTTP version
--libcurl Output libcurl code instead
-n Output notes after command line
-s Use short command line options
-v Add a verbose option to the command line
Where do you get the valid headers?
You can copy and paste the request headers from the browser. Open your favorite browser and launch the Developer Tools and go to Network tab.
Select the request and navigate to the Request Headers section to copy the source format of the headers as shown below, and then save it as a file.
If you would like to copy the cURL command directly from the browser, you can right-click on the request where you can see the cURL options as shown below.
Click on copy as cURL(cmd).
If you would like to create a JMeter test plan, launch JMeter, go to Tool > Import from cURL and enter the command as shown below.
Click on Create Test Plan which will create an HTTP Request Sampler and the HTTP Header Manager element.
Conclusion
cURL is a great utility for a quick smoke test and for automating stuffs. In performance testing, you can create cURL commands directly from the browser, or from the request headers. In JMeter, you can createa test plan directly from the cURL command.
Top comments (1)
Not that Import from cURL feature only available with Jmeter 5.1 onward.