日期:2014-05-16  浏览次数:20883 次

Apache AB 如何传递参数

AB使用时,网上通篇一律,在进行示例时使用的连接一般都是http://*.com,这种写法是没有带参数,如果你想测试一个写入的Case,那需要传递参数给后台,如何传递参数呢?

这里有一个登录的请求,需要登录名和密码,路径是这样的:

http://*/login.action?userName=admin&userPassWord=admin

使用该连接进行测试:ab -n 1 http://*/login.action?userName=admin&userPassWord=admin

发现由于存在特殊字符 & ,虽然命令执行成功,但是并不能处理 & 后的参数

?

关于AB使用的官网:http://httpd.apache.org/docs/2.0/programs/ab.html

他有两个参数:p(小写),T(大写),注意区分大小写,一个是用于指定POST请求时的参数文件,一个用于指定请求的类型Content-type,关于Content-type的类型,大家可以百度。

在AB命同级目录建立一个文件:para.txt,在里面写入要传递的参数:userName=admin&userPassWord=admin

指定请求类型为:application/x-www-form-urlencoded

?

完整的命令为:ab -n 1 -p para.txt -T application/x-www-form-urlencoded http://*/login.action?

如此就可以将需要的两个参数传递到后台

?

请您到ITEYE网站看原创,谢谢!

http://cuisuqiang.iteye.com/?!?

1 楼 cuisuqiang 2013-09-04  
ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving