Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting `Cannot mix POST with other methods` error when using `ab -p`

I'm using ApacheBench (ab) to stress test my site. When I specify a method -m POST and some postdata -p {datafile}, I get the message

Cannot mix POST with other methods.

The trouble is that I'm not actually mixing POST with other methods. Here's my full command:

ab -m POST -p postdata.txt -n 1000 -c 100 http://example.com/
like image 731
Paul d'Aoust Avatar asked Nov 24 '16 20:11

Paul d'Aoust


1 Answers

This is due to an idiosyncrasy in the way ab handles command-line arguments. When you use -p it automatically sets the method to POST for you, and this happens before -m is parsed. So when it parses -m, it sees that the already set method is not null and throws an error. What it should do (IMO) is silently ignore the parameter if its value is the same as what's implicitly been set.

Note that everything above also applies when you try to do a PUT request; e.g., ab -m PUT -u putdata.txt.

So what you should do to avoid this error is never specify -m when you're using -p or -u.

(Source: the ab.c source file)

like image 133
Paul d'Aoust Avatar answered Sep 30 '22 17:09

Paul d'Aoust