python 测试http post 的速度
import sys,httplib
from time import time
params = "*"*(512*1024)
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)",
"Connection": "Keep-Alive",
"Cache-Control": "no-cache"
}
count = 0
totalspeed = 0.0
m_postSpeed = 0.0
print len(params)
for i in range(1, 10):
start = time()
con2 = httplib.HTTPConnection("some.com")
con2.request("POST", "/test.aspx", params, headers)
r2 = con2.getresponse()
endtime = time()
if r2.status == 200:
#print "Success", "\n"
m_postSpeed = 8*512*1024 / (endtime-start)
totalspeed += m_postSpeed
count+=1
print m_postSpeed,"\n"
else:
print "Failed", "\n"
con2.close()
print "adv:%.2f" % (totalspeed / count)
上面的写法有啥问题没有?