Send HTTP Request with python
Before I wrote python http client with python socket in this article, but this is not a socket version, using httplib.
GET
connection = httplib.HTTPSConnection(host) connection.request("GET", uri) response = json.loads(connection.getresponse().read()) print response
POST
requestHeader = {"Content-type": "application/x-www-form-urlencoded"} connection = httplib.HTTPSConnection(host) connection.request("POST", uri, parameters, requestHeader) response = json.loads(connection.getresponse().read()) print response
POST requires content-type indicating as what kind of data I'm going to post. application/x-www-form-urlencoded is the most basic one. If uploading JSON data, requestHeader should be like below.
requestHeader = {"Content-type":"application/json"}