How Can I Do Post Request In Django?
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 user
Solution 1:
You didn't set url.
data = {
"username": "user",
"password": "pass",
}
URL = 'http://example.com'
r = requests.post(URL, data=data)
Solution 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()
Post a Comment for "How Can I Do Post Request In Django?"