I am trying to populate a database with results obtained by my python script. I am sending the gzipped data in POST request.
A PHP script acts in the middle as web services and needs to extract the gzip data and get 'sql-query' and do the further process.
This is what I am trying to do on Python side :
Sending a POST request using urllib:
# Data to be sent in POST request, it can be a SQL UPDATE/INSERT or SELECT
dictheaders = {'sql': "UPDATE 'logs' SET 'some_value' = Failed"}
# Encode the data
data = urllib.urlencode(dictheaders)
# Gzip compress the encoded data
IO = StringIO.StringIO()
gzip_data = gzip.GzipFile(fileobj=IO, mode='w')
gzip_data.write(data)
gzip_data.close()
gzip_data = IO.getvalue()
# This is the POST request being sent to a PHP web services file which
# needs to extract the gzipped query and then execute the query on SQL
f = urllib2.urlopen('http://x.x.x.x/example.php', gzip_data)
Following are the changes I have tried on PHP side:
$postdata = file_get_contents("php://input");
$a = gzinflate(substr(substr($postdata, 10), 0, -8));
$sql = $a['sql'];
The above code does not seem to be compatible with my Python code. Is this the right way to extract the gzip POST request in PHP ?