I am using Python and try to send a dictionary (that contains dynamic data) via HTTP-Post request to the server. What is the most efficient way to implement it?
Use urllib.urlencode
to encode the dictionary as a POST.
import urllib
import urllib2
mydict = {'key1': 'value1', 'key2': 'value2'}
encoded_dict = urllib.urlencode(mydict)
request = urllib2.Request(myurl, encoded_dict)
# now make the request
response = request.urlopen().read()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With