How to pass Headers and x-www-form-urlencoded body in Autocannon

4.9k Views Asked by At

I'm trying to pass Headers and x-www-form-urlencoded body in Autocannon POST request, but my response is always:

0 2xx responses, 5 non 2xx responses

Example from command line:

autocannon -c 1 -a 5 -H Authorization="Bearer xxxx",Content-Type="application/x-www-form-urlencoded" -b "Key"="Value" http://host.com:8080/path
2

There are 2 best solutions below

0
Shivjeet Singh On

Use -H flag for each header like this : autocannon -c 1 -a 5 -H "Authorization":"Bearer xxxx" -H "Content-Type":"application/x-www-form-urlencoded" -b '{"Key"="Value"}' http://host.com:8080/path

0
ObiHill On

Let's say you have the following data and you want to make a POST request using x-www-form-urlencoded:

URL https://api.something.com

Headers Authorization: Bearer some-extra-long-uuid= Content-Type: application/x-www-form-urlencoded

Body field_1: value_1 field_2: value_2

For the above data, the autocannon CLI command would look something like below:

autocannon -m POST -H "Authorization":"Bearer some-extra-long-uuid=" -H "Content-Type":"application/x-www-form-urlencoded" -b "field_1=value_1&field_2=value_2" https://api.something.com