双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

python 测试http post 的速度

Crazy_ing Crazy_ing 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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)

上面的写法有啥问题没有?
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
Crazy_ing
脚本语言 37,738 成员 34,208 内容