Paul d'Aoust
Paul d'Aoust

Reputation: 3209

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/

Upvotes: 6

Views: 1473

Answers (1)

Paul d'Aoust
Paul d'Aoust

Reputation: 3209

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)

Upvotes: 13

Related Questions