970_90

Saturday, 2 May 2015

How to set authorization header in Curl using zend framework

 How to set authorization header in Curl using zend framework

 How to set authorization header in Curl using Zend Framework
   $url ='www.domain.com/web-service-API';
  $config = array(
        'adapter' => 'Zend_Http_Client_Adapter_Curl',
        'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,CURLOPT_SSL_VERIFYPEER =>FALSE),            
    );
    
    $client = new Zend_Http_Client($url, $config);
    //Set the Header value
    $client->setAuth('username', 'password!');
    
    $response = $client->request('GET'); 
    echo $response->getBody();



Set header (Name & Value) in curl using Zend Framework
$url ='www.domain.com/web-service-API';
  $config = array(
        'adapter' => 'Zend_Http_Client_Adapter_Curl',
        'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,CURLOPT_SSL_VERIFYPEER =>FALSE),            
    );
    
    $client = new Zend_Http_Client($url, $config);
    //Set the Header value
    $client->setHeaders('HEADER-NAME', 'Header-Value');
    
    $response = $client->request('GET'); //Here you can set GET Method Also
    echo $response->getBody();   



Send the JSON Data in curl using Zend Framework
$url ='www.domain.com/web-service-API';
$json = json_encode(array('name'=>'Web','age'=>20));
  $config = array(
        'adapter' => 'Zend_Http_Client_Adapter_Curl',
        'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,CURLOPT_SSL_VERIFYPEER =>FALSE),            
    );
    $response = $client->setRawData($json, 'application/json')->request('POST');
    echo $response->getBody();




No comments:

Post a Comment