3

I call Curl in my code. Please have a look

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
public function __construct(

            \Magento\Framework\HTTP\Adapter\Curl $httpAdapter
) {
    $this->_httpAdapter = $httpAdapter;
}
    public function createBookingNumber($service,$order)
            {
 $config = array('timeout' => 60);
 $this->_httpAdapter->setConfig($config);
    $this->_httpAdapter->addOption(CURLOPT_RETURNTRANSFER, 1);
    $this->_httpAdapter->addOption(CURLOPT_HEADER,0);
    $this->_httpAdapter->addOption(CURLOPT_POST,1);
$this->_httpAdapter->write(\Zend_Http_Client::POST, 'myapi url', '1.1',array("Authorization: Basic cm9iaW5sYXVAcG9zdG5ldC5jb20uYXU6TWFnaWNtYW4yMTEwNzU=",
  "Content-Type: application/json"), json_encode($data));  // $data is an array which I need to convert in jeson and send.

    $response = $this->_httpAdapter->read();
    print_r($response);
    $this->_httpAdapter->close(); 
}

}

But when I print my response I am getting header too, but I set false in my code.

My Response :

HTTP/1.1 200 OKDate: Tue, 10 Jan 2017 10:42:04 GMTServer: Apache/2.4.7 (Ubuntu)Vary: Authorization,Accept-EncodingX-Powered-By: PHP/5.5.9-1ubuntu4.17Cache-Control: no-cacheSet-Cookie: XSRF-TOKEN=eyJpdiI6IjFxQ05ZZUpIQVFUWU4wWU9ZaW16cHc9PSIsInZhbHVlIjoiaVFCZVhwZ01HN3laUDhwSGFcL0Z6Z1lsOTd6VUxsXC93REFiXC8yMThlRVk1cklRUmQxVmlYaGlibjdVU25rNkxMY3BHTmJWVTJrazl6YVwvMnJOWTZYaHJBPT0iLCJtYWMiOiI3ZWZjYmU3ZTZkMmJhMWVkOWE4OTFmMzliMTNhZDg2ZjE5ODE5NzE3NDNlN2U2MzkyZDBmM2Q2YjcwOTE0MGJhIn0=; expires=Tue, 10-Jan-2017 12:42:12 GMT; Max-Age=7200; path=/Set-Cookie: laravel_session=236088dea752bc581c762a9448febf1eb085fc2c; expires=Tue, 10-Jan-2017 12:42:12 GMT; Max-Age=7200; path=/; httponlyTransfer-Encoding: chunkedContent-Type: text/html; charset=UTF-8.{"status":"ok","response":{"user_id":17,"vendor":"dhlcp","description":"","tracking_no":"CPWEXPD000000131","label_pdf":"JVBERi0xLjQKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL01lZGlhQm94IFswIDAgNDIwLjAwIDU5NS4wMF0KL1Jlc291cmNlcyAyIDAgUgovQ29udGVudHMgNCAwIFI+

Can you please help.

0

You just need to add header = '' in your config variable......

public function createBookingNumber($service,$order)
 {
 $config = array('timeout' => 60,'header'=>'');
 $this->_httpAdapter->setConfig($config);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.