python多线程get与post请求模板代码
来源:互联网 发布:淘宝网首页秋水伊人 编辑:程序博客网 时间:2024/05/20 00:35
post请求模板代码:
#coding=utf-8'''random.randint(a, b):用于生成一个指定范围内的整数。其中参数a是下限,参数b是上限,生成的随机数n: a <= n <= brandom.choice(sequence):从序列中获取一个随机元素参数sequence表示一个有序类型(列表,元组,字符串)'''import httplib,urllibfrom time import ctime import threading#from random import randint,choice #创建请求函数def postRequest(): postJson={ } #定义需要进行发送的数据 params = urllib.urlencode(postJson); #定义一些文件头 headers = { } #接口 requrl ="" #请求服务,例如:www.baidu.com hostServer="" #连接服务器 conn = httplib.HTTPConnection(hostServer) #发送请求 conn.request(method="POST",url=requrl,body=params,headers=headers) #获取请求响应 response=conn.getresponse() #打印请求状态 if response.status in range(200,300): pass #创建数组存放线程 threads=[] #创建100个线程for i in range(100): #针对函数创建线程 t=threading.Thread(target=postRequest,args=()) #把创建的线程加入线程组 threads.append(t) if __name__ == '__main__': #启动线程 for i in threads: i.start() #keep thread for i in threads: i.join()
get请求模板代码:
#coding=utf-8'''random.randint(a, b):用于生成一个指定范围内的整数。其中参数a是下限,参数b是上限,生成的随机数n: a <= n <= brandom.choice(sequence):从序列中获取一个随机元素参数sequence表示一个有序类型(列表,元组,字符串)'''import httplib,urllibfrom time import ctime import threading#from random import randint,choice #创建请求函数def getRequest(): #定义一些文件头 headers = { } #请求服务,例如:www.baidu.com hostServer="" #接口 requrl ="" #连接服务器 conn = httplib.HTTPConnection(hostServer) #发送请求 conn.request(method="GET",url=requrl,headers=headers) #获取请求响应 response=conn.getresponse() #打印请求状态 if response.status in range(200,300): pass #创建数组存放线程 threads=[] #创建100个线程for i in range(100): #针对函数创建线程 t=threading.Thread(target=getRequest,args=()) #把创建的线程加入线程组 threads.append(t) if __name__ == '__main__': #启动线程 for i in threads: i.start() #keep thread for i in threads: i.join()
以上方法,只适用于基本的,其他的需要进行自己修改!
阅读全文
0 0
- python多线程get与post请求模板代码
- 【python】GET请求与POST请求
- post get 请求 模板
- python post/get 请求
- post与get请求
- get请求与post请求
- post请求与get请求
- GET请求与POST请求
- python get post模拟请求
- Python GET或者POST 请求
- python get和post请求
- Python - Http Get Post请求
- Python发送get,post请求
- Python--get和post请求
- Python向PHP发起GET与POST请求
- Get与Post请求区别:
- Get与Post请求区别
- 浅析get与post请求
- canvas实现方块运动
- 文章标题
- 基于单链表和基于环形队列的生产者消费者模型
- Android studio使用javah找不到类文件问题
- 针对实践(一)代码的修改
- python多线程get与post请求模板代码
- 慎用MySQL子查询,尤其是看到DEPENDENT SUBQUERY标记时
- mysql数据库开启慢查询
- 生产者与消费者模型
- hadoop-2.x高可用集群搭架
- matlab 全部的随机数函数
- Python3连接数据库
- Mac下RabbitMQ安装
- 方法