Python request带Payload POST

2024-06-11阅读数:225
上一篇:Python requests添加User Agent
下一篇:Python读写文本文件
# coding=utf-8
import requests
 
def post_payload(url, payload):
myheaders = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36'}
response = requests.post(url, headers=myheaders, data=payload)
status_code = response.status_code
if status_code != 200:
print(f'post failed: {status_code}', status_code)
return ''
return response.text
 
if __name__ == '__main__':
payload = {'username':'admin','password':'123456'}
content = post_payload('http://www.example.com', payload)
print(content)