使用python批量发送post请求

#!/usr/bin/env python
import requests
url="http://192.168.26.xxx"
header={
            'Connection':'close',
	        'Accept':'application/json,image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*',
	        'User-Agent':'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)',
            "Content-Type": "application/json; charset=UTF-8"
}

"""
body='{"11111":"onactivate="}'

re=requests.post(url=url,headers=header,data=body)
print(re)

"""
#请求json报文体
dict=[
'{"11111":"onactivate="}',
'{"11111":"onafterprint="}',
'{"11111":"onbeforeactivate ="}',
'{"11111":"onbeforeunload="}',
'{"11111":"onblur="}',
'{"11111":"oncancel="}',
'{"11111":"oncanplaythrough="}',
'{"11111":"oncanplay="}',
'{"11111":"onchange="}',
'{"11111":"onclick="}',
'{"11111":"oncontextmenu="}',
'{"11111":"oncopy="}',
'{"11111":"oncuechange="}',
'{"11111":"oncut="}',
'{"11111":"ondblclick="}',
'{"11111":"ondragdrop="}',
'{"11111":"ondragend="}',
'{"11111":"onondragenter="}',
'{"11111":"ondragleave="}',
'{"11111":"ondragstart="}',
'{"11111":"ondrag="}',
'{"11111":"ondrop="}',
'{"11111":"ondurationchange="}',
'{"11111":"onemptied="}',
'{"11111":"onerror="}',
'{"11111":"onfocus="}',
'{"11111":"onformchange="}',
'{"11111":"onforminput="}',
'{"11111":"onhashchange="}',
'{"11111":"oninput="}',
'{"11111":"onkeydown="}',
'{"11111":"onkeypress="}',
'{"11111":"onkeyup="}',
'{"11111":"onloadeddata="}',
'{"11111":"onloadedmetadata="}',
'{"11111":"onloadstart="}',
'{"11111":"onload="}',
'{"11111":"onmessage="}',
'{"11111":"onmousedown="}',
'{"11111":"onmouseenter="}',
'{"11111":"onmouseleave="}',
'{"11111":"onmousemove="}',
'{"11111":"onmouseout="}',
'{"11111":"onmouseover="}',
'{"11111":"onmousewheel="}',
'{"11111":"onmove="}',
'{"11111":"onoffline="}',
'{"11111":"ononline="}',
'{"11111":"onpagehide="}',
'{"11111":"onpageshow="}',
'{"11111":"onpaste="}',
'{"11111":"onpause="}',
'{"11111":"onplaying="}',
'{"11111":"onplay="}',
'{"11111":"onpopstate="}',
'{"11111":"onprogress="}',
'{"11111":"onpropertychange="}',
'{"11111":"onreset="}',
'{"11111":"onresize="}',
'{"11111":"onscroll="}',
'{"11111":"onsearch="}',
'{"11111":"onseeked="}',
'{"11111":"onseeking="}',
'{"11111":"onselect="}',
'{"11111":"onshow="}',
'{"11111":"onstalled="}',
'{"11111":"onstart="}',
'{"11111":"onstorage="}',
'{"11111":"onsubmit="}',
'{"11111":"onsuspend="}',
'{"11111":"ontimeupdate="}',
'{"11111":"ontoggle="}',
'{"11111":"onunload="}',
'{"11111":"onvolumechange="}',
'{"11111":"onwaiting="}',
'{"11111":"onwheel="}',
'{"11111":"onbeforeprint="}',
'{"11111":"onbeforeactivate ="}',
'{"11111":"onended="}',
'{"11111":"oninvalid="}',
'{"11111":"onmouseup="}',
'{"11111":"ondratechange="}',
'{"11111":"onreadystatechange="}'
]
print(dict)
count=0
list=[]
for i in dict:
    response=requests.post(url=url,headers=header,data=i)
    count += 1
    #获取响应状态码
    print(response.status_code)
    if(response.status_code==200):
        list.append(count)

    print("这是第:{0} 次发送".format(count))

print("测试结束,下面是测试实效的序号")
print(list)

 

你可能感兴趣的:(python)