Search code examples
apachehttpapachebench

Apache Bench POST: Is it possible to read from string or stdin, instead of a file?


I have an Apache Bench POST test command like: ab -p test.json -n 1000 -c 100 -T "application/json" "http://localhost:8080/test"

However, my test.json is very simple, e.g.: {"foo": 1}

Is it possible to read that in directly to the ab command, without a file reference? Something like: ab -p '{"foo": 1}' -n 1000 -c 100 -T "application/json" "http://localhost:8080/test"

(I know that doesn't work, just wondering if there is a good linux file mimic trick or something)

My only workaround currently is: echo '{"foo": 1}' > test.json && ab -p test.json -n 1000 -c 100 -T "application/json" "http://localhost:8080/test" && rm test.json

But I find that a bit too clunky.


Solution

  • Try:

    cat test.json | ab -p /dev/stdin -n 1000 -c 100 -T "application/json" "http://localhost:8080/test"