Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send binary file as body? #382

Open
rewagner87 opened this issue May 6, 2019 · 4 comments
Open

How to send binary file as body? #382

rewagner87 opened this issue May 6, 2019 · 4 comments

Comments

@rewagner87
Copy link

rewagner87 commented May 6, 2019

Hello,

Has anyone been able to send the contents of a binary file as the request body with wrk?

I have been able to send the contents of a json file by doing this:

wrk.method = "POST"
local f = io.open("data.json", "r")
wrk.body   = f:read("*all")

But when I try to do something similar with a binary file like so:

wrk.method = "POST"
local f = assert(io.open("request.pb", "rb"))
wrk.body   = f:read("*all")

It doesn't seem to work. I'm able to use this same pb file with a curl command, but can't get it working quite right with wrk.

Any help would be greatly appreciated.

Thanks!

@letmaik
Copy link

letmaik commented Jun 15, 2021

This works as expected, just remove the assert:

wrk.method = "POST"
local f = io.open("request.pb", "rb")
wrk.body   = f:read("*all")

@tonytonyjan
Copy link

This works as expected, just remove the assert:

wrk.method = "POST"
local f = io.open("request.pb", "rb")
wrk.body   = f:read("*all")

Wouldn't this read the disk per request and affect performance?

@cowboy-bebug
Copy link

cowboy-bebug commented Nov 22, 2021

@tonytonyjan yeah it does look like it's adding some overhead (although I didn't measure the disk I/O):

$ wrk --threads=1 --connections=1 --duration=10s --script="using_io.lua" http://localhost:1234/test
Running 10s test @ http://localhost:3005/nzcp/v1/verify
  1 threads and 1 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   344.33ms   83.55ms 622.22ms   86.21%
    Req/Sec     2.66      0.72     4.00     86.21%
  29 requests in 10.02s, 16.06KB read
Requests/sec:      2.89
Transfer/sec:      1.60KB

$ wrk --threads=1 --connections=1 --duration=10s --script="using_static.lua" http://localhost:1234/test
Running 10s test @ http://localhost:3005/nzcp/v1/verify
  1 threads and 1 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   207.19ms   82.15ms 515.03ms   84.62%
    Req/Sec     5.18      2.70    10.00     67.35%
  49 requests in 10.05s, 26.22KB read
Requests/sec:      4.88
Transfer/sec:      2.61KB

Using hexdump into a file, regex and then passing raw bytes statically helped for me:

local pdf = "\x65\x72\x20\x5b..." -- eg, pdf
wrk.method = "POST"
wrk.body   = pdf
wrk.headers["Content-Type"] = "application/pdf"

@khurshid-alam
Copy link

khurshid-alam commented Aug 18, 2023

This doesn't works for with xml. Getting all 404 in response.

wrk.method = "POST"
local f = io.open("post_con_m2.xml", "r")
wrk.body   = f:read("*all")
wrk.headers["Content-Type"] = "application/xml"
wrk.headers["Accept"] = "application/xml"

wrk -t12 -c400 -d30s -s post.lua https://demo.example.com/HubWrapper/ConciseSearch:443

Any idea why ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants