python3 urllib.request.Request的用法


import urllib.request
import urllib.parse
 
url = 'http://127.0.0.1:8000/api/login/'
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) 
  AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
'} headers['Host'] = 'httpbin.org' dict = {'user': 'admin','pwd': '12345',} data = urllib.parse.urlencode(dict).encode('utf-8') #data参数如果要传必须传bytes(字节流)类型的,如果是一个字典,先用urllib.parse.urlencode()编码。 request = urllib.request.Request(url = url,data = data,headers = headers,method = 'POST') response = urllib.request.urlopen(request) html = response.read().decode('utf-8') print(html)

------------


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM