Friday, 15 January 2010

how to convert python httplib.HTTPSConnection to php -



how to convert python httplib.HTTPSConnection to php -

i want send post https request php ,similar request in python:

api_host = "android.clients.google.com" api_page = "/market/api/apirequest" parmas=params = urllib.urlencode({ "version" : 2, "request" : request }) headers = {"content-type": "application/x-www-form-urlencoded"} connection = httplib.httpsconnection( api_host ) connection.request( "post", api_page, params, headers ) resp = connection.getresponse().read() connection->close()

i tried lib https://github.com/dcramer/php-httplib

but lib , not back upwards https

my php code:

$query_data = array( "version" => 2, "request" => $request ); $params = http_build_query($query_data); $headers = array("content-type"=> "application/x-www-form-urlencoded"); $api_url = $api_host.$api_page; $ch = curl_init(); curl_setopt($ch, curlopt_url, $api_url); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $params); curl_setopt($ch, curlopt_ssl_verifypeer, 0); $resp = curl_exec($ch);

python code works, php code homecoming bad request, error 400

can seek this:

<?php // info $postfields = array( 'version' => 2, 'request' => $request ); // post $ch = curl_init(); curl_setopt($ch, curlopt_url, 'https://android.clients.google.com/market/api/apirequest'); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $postfields); curl_setopt($ch, curlopt_ssl_verifypeer, 0); $result = curl_exec($ch); curl_close($ch); // debug var_dump($result);

php python

No comments:

Post a Comment