Make a POST request using ab (apache benchmarking) on a django server

hermancaldara picture hermancaldara · Apr 19, 2015 · Viewed 37k times · Source

I'm trying to make a HTTP POST request using ab to a form built with django.

I'm using the following line:

ab -n 10 -C csrftoken=my_token -p ab_file.data -T application/x-www-form-urlencoded http://localhost:8000/

My ab_file.data looks like this:

url=my_encoded_url&csrfmiddlewaretoken=my_token

It always returns a 403 status code.

When I use curl using the same parameters, it works. The curl line:

curl -X POST -d "url=my_encoded_url&csrfmiddlewaretoken=my_token" --cookie "csrftoken=my_token" http://localhost:8000/

How can I do that?

Answer

jacobm654321 picture jacobm654321 · Apr 25, 2015

File must have a properly url-encode data. If you url-encode manually, it is too easy to have typos like blanks wrong encodes. Best do it programmatically. See an another answer: Apache Bench and POST data on how to use Python to create such file ( ex: post.data)

Then use: ab -T 'application/x-www-form-urlencoded' -n 10 -p post.data http://localhost:8080/