1. 程式人生 > >ab 傳送post請求 測試API效能

ab 傳送post請求 測試API效能

apache benchmark 工具 測試API 效能傳送 Post 請求(Linux環境驗證通過

在apache bin 目錄,在linux上執行命令:
./ab -n 1 -v 4 -p 'userlogin.txt' -T 'application/x-www-form-urlencoded' 'http://api.xxxxx.com/1/login'

說明:
(1)
userlogin.txt 這裡邊記錄是API的post請求的引數,放在和ab相同目錄下(/opt/app/apache-2.4.12/bin),內容如下,
user_name=639493678400&password=A1111111&cheers=1
(2)

  這個api只需要2個引數user_name,password,如果 引數檔案中寫成 user_name=639493678400&password=A1111111的話,還是報錯,所以又多傳了個引數cheers=1,這樣就不報錯了(和開發溝通下,說是佔位符的問題),這點非常重要。  

最後說明:在windows系統中,使用ab還是會報錯,所以大家注意,這個篇文章是針對Linux系統的。

---------------------------------------------------- 被測試API -----------------------------------------------------

Login
Login with username and password credential.
URLhttp://api.xxxxx.com/1/login
Request Method: POST
Request
Header

Field Required Description
User-Agent O User Agent of Client
X-User-Agent M Extend User Agent of Client
Body
Field Required Description
user_name M Name of user
password M Password of user credential
device O Login device id
pwd_flag O 1:encrypted 0:non-encrypted(default)

Body

Field Data Type Description
token string Access token for business interaction.
expires_in long Valid time range of access token. (Seconds)