I started to try wrk. It's very simple to use and very hard on the server, but I don't know how to perform other kind of request such as POST. In fact, I don't even know if this tool allows it. The documentation is very minimal.
Thanks
I started to try wrk. It's very simple to use and very hard on the server, but I don't know how to perform other kind of request such as POST. In fact, I don't even know if this tool allows it. The documentation is very minimal.
Thanks
This is possible now. Here is an example https://github.com/wg/wrk/blob/master/scripts/post.lua.
wrk.method = "POST"
wrk.body = "foo=bar&baz=quux"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
save this in a *.lua
script and pass it into your command line test with the -s
flag.
for those looking for a content-type "application/json" example:
wrk.method = "POST"
wrk.body = '{"firstKey": "somedata", "secondKey": "somedata"}'
wrk.headers["Content-Type"] = "application/json"
wrk.body = '{"firstKey": "somedata", "secondKey": "somedata"}'
–
Bareback Here's an example lua script post_binary.lua
for posting binary file: "Content-Type:application/octet-stream"
.
wrk.method = "POST"
wrk.headers["Content-Type"] = "application/octet-stream"
file = io.open("dog.jpg", "rb")
wrk.body = file:read("*a")
Then try: wrk "your_url" -s post_binary.lua --latency -t 1 -c 1 -d 30s -R 1
I'll recommend using wrk2
instead of wrk
since wrk2 provides better support for concurrent requests. When content-type
header is application/json
then please escape the special characters like \n
with \\n
and all other special characters present. Not doing this will send an invalid json to the upstream API, which will waste your time debugging.
Create a file with extension lua
and paste the following in it. Save it and pass it along with -s
flag to wrk2 command.
wrk.method = "POST"
wrk.body = "{\"firstKey\": 'somedata', \"secondKey\": 'somedata'}"
wrk.headers["Content-Type"] = "application/json"
Also you can add multiple header as
wrk.headers["Header1"] = "Header1_Val"
wrk.headers["Header2"] = "Header2_Val"
wrk.headers["Header3"] = "Header3_Val"
wrk.headers["Header4"] = "Header4_Val"
wrk2 -t500 -c1000 -d160s -R10000 -s ~/Documents/luaTestScript.lua http://localhost:8080/test_endpoint
© 2022 - 2024 — McMap. All rights reserved.