问题
with exception of requests, are there other ways for doing a POST HttpRequest?
I CAN ONLY USE DJANGO LIBS, so I cannot import requests
.
In particular, I would like to pass the username and the password in the post request. something like:
data = {
"username": "user",
"password": "pass",
}
r = request.POST( data )
(please note that this code is just an example)
Anyone knows?
note: I'm using python 2.7
回答1:
You didn't set url.
data = {
"username": "user",
"password": "pass",
}
URL = 'http://example.com'
r = requests.post(URL, data=data)
回答2:
If you cannot use requests, try using urllib2 and urllib. What do you think about this?
post_data = {
"username": "user",
"password": "pass",
}
result = urllib2.urlopen('http://example.com', urllib.urlencode(post_data))
content = result.read()
来源:https://stackoverflow.com/questions/48751113/how-can-i-do-post-request-in-django