python實現多線程post方法進行壓
#coding=utf-8 import httplib,urllib from time import ctime import threading import csv postJson={ } #定義需要進行發送的數據 params = urllib.urlencode(postJson); #定義一些文件頭 headers = {"Content-Type":"application/x-www-form-urlencoded", "Connection":"Keep-Alive" } #創建請求函數 def Clean(): #接口的url requrl ="" #連接服務器 conn = httplib.HTTPConnection("") #發送請求 conn.request(method="POST",url=requrl,body=params,headers=headers) #獲取請求響應 response=conn.getresponse() #打印請求狀態 print response.status #創建數組存放線程 threads=[] #創建100個線程 for i in range(100): #針對函數創建線程 t=threading.Thread(target=Clean,args=()) #把創建的線程加入線程組 threads.append(t) print 'start:', ctime() if __name__ == '__main__': #啟動線程 for i in threads: i.start() #keep thread for i in threads: i.join() print 'end:', ctime() #Url.close()