# 简单例子
import urllib.request
request = urllib.request.Request('https://python.org')
response = urllib.request.urlopen(request)
# print(response.read().decode('utf-8'))
# 增加header
from urllib import request, parse
# url = 'http://httpbin.org/post'
url = 'https://upload.wikimedia.org/wikipedia/commons/e/e0/Caravaggio_-_Cena_in_Emmaus.jpg'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0'
}
# 构造POST表格
dict = {
'name': 'Germey'
}
data = bytes(parse.urlencode(dict), encoding='utf8')
req = request.Request(url=url, data=data, headers=headers, method='GET')
response = request.urlopen(req)
print(response)