1. 程式人生 > >Apache ab使用POST引數進行壓力測試

Apache ab使用POST引數進行壓力測試

傳遞POST引數的步驟:

1,新建一個檔案,裡面放入POST引數。

注意,這個承載POST引數的檔案,不依賴於字尾名。可跨平臺(比如 Linux 下用 vi 建立的檔案,win下也可以用)

POST文字內容如下:

name=chang&password=11111ok

我把這個文字儲存成 postdata.txt ,放到了win機器下的 F盤 下。

2,使用ab命令

ab -n 1 -c 1 -p f:/postdata.txt -T application/x-www-form-urlencoded "http://127.0.0.1/abpost"

例如win下:


上面命令的簡單說明:

-n 測試幾次(Number of requests to perform for the benchmarking session. The default is to just perform a single request which usually leads to non-representative benchmarking results.)

-c 模擬多少客戶端(Number of multiple requests to perform at a time. Default is one request at a time.)

-T 內容型別。這個一般和-p 一起使用(Content-type header to use for POST data.)

-p 包含POST引數的檔案(File containing data to POST.)

注意,最後的 URL 需要加引號。

控制檯的列印結果:

OK,可以正常接收到POST引數,進行壓測了! 

-----------------------------------------------------------------------------------------------

Ps: 加上-V引數(一般取值為4),會把返回的狀態打印出來,如下。但是每個請求測試都列印,有點煩。

LOG: Response code = 200
LOG: header received:
HTTP/1.0 200 OK
Date: Thu, 07 Jul 2016 06:11:06 GMT
Server: WSGIServer/0.1 Python/2.7.11
X-Frame-Options: SAMEORIGIN
Content-Type: text/html; charset=utf-8