Tuesday, May 21, 2013

How to post data using curl / Zend_Http_Client

using curl
$data = array("name" => "Hagrid", "age" => "36");     
$jsonData = json_encode($data);
$handle = curl_init();
$url = 'http://magento.com/customer/account/login';
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
using Zend_Http_Client
// new HTTP request to some HTTP address
$client = new Zend_Http_Client($url);
// set some parameters
$client->setParameterPost('data', $jsonData);
// POST request
$client->request(Zend_Http_Client::POST);

No comments:

Post a Comment