Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Bench and POST data

i am trying to use apache bench to load test a create action in my rails application but ab doesn't appear to be sending the POST data - though it does correctly submit a POST and not a GET request.

this is the command i run:

ab -n 1 -p post -v 4 "http://oz01.zappos.net/registrations"

and this is the contents of the post file:

authenticity_token=M18KXwSOuIVbDPZOVQy5h8aSGoU159V9S5uV2lpsAI0

the rails logs show a POST request coming through but don't show any parameters being posted:

Started POST "/registrations" for 10.66.210.70 at Thu Sep 09 17:48:06 -0700 2010
  Processing by RegistrationsController#create as */*
Rendered registrations/new.html.erb within layouts/application (14.0ms)
Completed 200 OK in 24ms (Views: 14.6ms | ActiveRecord: 0.1ms)

whereas a POST request coming from a browser results in this log entry:

Started POST "/registrations" for 192.168.66.20 at Thu Sep 09 17:49:47 -0700 2010
  Processing by RegistrationsController#create as HTML
  Parameters: {"submit"=>"true", "authenticity_token"=>"AfNG0UoTbJXnxke2725efhYAoi3ogddMC7Uqu5mAui0=", "utf8"=>"\342\234\223", "registration"=>{"city"=>"", "address"=>"", "name"=>"", "zip"=>"", "optin"=>"0", "state"=>"", "email"=>""}}
Rendered registrations/new.html.erb within layouts/application (13.7ms)
Completed 200 OK in 24ms (Views: 14.3ms | ActiveRecord: 0.1ms)

and finally, this is what ab logs for the request:

---
POST /registrations HTTP/1.0
User-Agent: ApacheBench/2.0.40-dev
Host: oz01.zappos.net
Accept: */*
Content-length: 63
Content-type: text/plain


---

why is it not picking up the post data?

if the "post" file is not there then i get an error message saying it can't find the file so i know at very least it is finding the file...

like image 864
emh Avatar asked Sep 10 '10 07:09

emh


2 Answers

Maybe you need the -T option as stated in man ab:-

ab -n 1 -p post -v 4 -T application/x-www-form-urlencoded "http://oz01.zappos.net/registrations"

I tested with Django and it seem that Django don't really care about the content type header (it displayed the POSTed content whether I used -T or not) but Rails maybe want it.

like image 120
k4ml Avatar answered Oct 19 '22 22:10

k4ml


Old question, but for the sake of anyone else who searches SO for this, here's how I got it to work.

Make EXTRA sure your post file is properly URL encoded with no extra non-printing characters or anything at the end. The most error-free way is just create it with code. I used some python to create mine:

>>> import urllib
>>> outfile = open('post.data', 'w')
>>> params = ({ 'auth_token': 'somelongstringthatendswithanequalssign=' })
>>> encoded = urllib.urlencode(params)
>>> outfile.write(encoded)
>>> outfile.close()

Example output:

auth_token=somelongstringthatendswithanequalssign%3D
like image 21
Troy Avatar answered Oct 19 '22 22:10

Troy