Hi,
I have to POST a request to a server. In the API documentation of the website there is this example that uses cURL in PHP:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.website.com');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "request=$wrapper");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
;
$data = curl_exec($ch);
curl_close($ch);
But my app is done using Python, so I tried to write something like that but this code doesn't work:
req = urllib2.Request(url, formatted)
response = urllib2.urlopen(req)
html = response.read()
print html+"\n\n"
Can you help me write a working conversion of a PHP cURL program to Python?
Thank you!!