python 测试http post 的速度

Crazy_ing 2008-07-10 03:30:42
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)

上面的写法有啥问题没有?
...全文
514 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
SenerityChzr 2008-11-28
  • 打赏
  • 举报
回复
mark
speme 2008-09-02
  • 打赏
  • 举报
回复
问题是,你POST过去那么多*号干嘛?
juebanliaoshen 2008-08-22
  • 打赏
  • 举报
回复
看不明白!
iambic 2008-07-11
  • 打赏
  • 举报
回复
你自己的测试结果?

37,708

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧