早上好, 我已经做到了...我可以发送带有标题和正文信息的请求。但不幸的是,某些URL需要Cookies。如何将硬编码的Cookie放在urllib.request中。
url = "https://example.de"
values = {"username": "TestKunde1","password": "Password1"}
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
##Cookies = ??????? like something like Cookies = dict(authHint=num; path=/; domain=text; secrue;
body = json.dumps(values).encode("utf-8")
#pprint(data)
try:
req = urllib.request.Request(url, body, headers)
with urllib.request.urlopen(req) as f:
res = f.read()
pprint(res.decode())
except Exception as e:
pprint(e)
´´´