python批量请求(GET | POST)

2023-05-16

本案例为普通的测试案例,主要用于测试通过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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python批量请求(GET | POST) 的相关文章

随机推荐