使用urllib库的request模拟发送请求
它是 Python 内置的 HTTP 请求库,也就是说我们不需要额外安装即可使用
示例代码如下:
1 from urllib import request, parse 2 url = 'https://XX.XXXX.com/XX/XX/uaa/login' 3 headers = { 4 "x-app-id": "******" 5 } 6 dict = { 7 'username': '*******', 8 "password": "******" 9 } 10 data = bytes(parse.urlencode(dict), encoding='utf8') 11 req = request.Request(url=url, data=data, headers=headers, method='POST') 12 response = request.urlopen(req) 13 print(response.read().decode('utf-8'))