python批量请求(GET

514次阅读
没有评论
python批量请求(GET

本案例为普通的测试案例,主要用于测试通过get请求和post请求产生响应是否一致,主要针对响应码为200的结果进行输出,没有什么技术含量!

#-*- coding:utf-8 -*-

import requests def apiRequest(): header = { 'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36', 'Cookie': 'JSESSIONID=E65BD767F22CBEFE30BAF33D84A59072', 'Referer':'http://aaa.xxx.com', 'Content-Type':'application/json;' } with open('url.txt','r',encoding='utf-8') as fp: urls = fp.readlines() for li in urls:

get_response = requests.get(url=li,headers=header) post_response = requests.post(url=li, headers=header)

if get_response.status_code == 200 or post_response.status_code == 200: print(li.strip()+"请求测试结果如下:") print("GET请求测试结果",get_response.content) print("POST请求测试结果", post_response.content) if __name__ == '__main__': apiRequest()

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:Python基础教程2022-11-22发表,共计867字。
新手QQ群:570568346,欢迎进群讨论 Python51学习