Sending an HTTP POST Request


How to send an HTTP POST request? I want to submit a form to a Website.



To submit a form to a Website, you can use the function:

>>> r =, data = {'key':'value'})

The second argument 'data' is a 'dict' object contains of the list of form field names and values.

Here is a Python example on how to send a POST request and print the response body in JSON formation:

>>> import requests
>>> form = {'userid':'fyi', 'password':'center'}
>>> r ='',data=form)
>>> j = r.json()
>>> print(j)
{'args': {}, 'data': '', 
 'files': {}, 
 'form': {'password': 'center', 'userid': 'fyi'}, 
 'headers': {
  'Accept': '*/*', 
  'Accept-Encoding': 'gzip, deflate', 
  'Connection': 'close', 
  'Content-Length': '26', 
  'Content-Type': 'application/x-www-form-urlencoded', 
  'Host': '', 
  'User-Agent': 'python-requests/2.19.1'
 'json': None, 
 'url': ''


Accessing the HTTP Request Object

requests.models.Response Objects

'requests' Module - HTTP for Humans

⇑⇑ Python Tutorials

2018-08-14, 152👍, 0💬