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)
上面的写法有啥问题没有?
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)
上面的写法有啥问题没有?
...全文
相关推荐
Python-CmonOptus一个用于测试网速的Python3脚本
CmonOptus一个用于测试网速的Python3脚本
HTTPretty:适用于Python的HTTP客户端模拟工具-受Fakeweb for Ruby的启发
HTTPretty:适用于Python的HTTP客户端模拟工具-受Fakeweb for Ruby的启发
Python requests模块安装及使用教程图解
requests模块是一个用于访问网络的模块,其实类似的模块还有很多,不在一一在这里解释。这么多的相似的模块为什么都说只有这个好用呢,因为他人性化。如果你学过urllib之类的模块的话,比如urllib,对比一下就很清楚了。 1、requests模块的安装 requests模块的安装非常简单,使用pip install requests命令即可安装,我是在python的Terminal中直接安装的,大家也可以在cmd命令窗口中进行安装。 2、requests模块的导入 导入requests模块时,直接使用import requests 命令进行导入即可,导入后就可以使用啦。 3、reque
基于Python实现的单独测试某一个CDN ip的速度,支持多线程,可自定义时间或流量
基于Python实现的单独测试某一个CDN ip的速度,支持多线程,可自定义时间或流量,你也可以用于测试你的网络速度
python web接口开发与测试
虫师的一本关于web 接口测试的书籍,推荐给大家,基于python语言



