Using CURL Functions in magento way

PHP CURL library is used to fetch third party contents, transfer files and post data. Magento Wraps the CURL Functions in its library with its own wrapper functions. There is no Hard and Fast Rule that we need to only use this function, but the magento core code makes use of this library.
Varien_Http_Adapter_Curl class is responsible for providing the wrapper functions.

Let’s see some code snippets to understand how it works.

The above code fetches the lastest information on magento blog in xml format. The $curl->write function accepts the method name (GET,POST), URL,HTTP version,headers,body etc. The $curl->read function will execute the curl_exec() internally.

  1. Tim says:

    Thx for sharing.

  2. How can you add $_POST variables with that method?

    in PHP only you can use this:

    but how to use it the magento way?

    • I just figured it out a while ago…

      anyway I’ll post the codes for anyone who passed by here:

      $curl->write(Zend_Http_Client::GET, $feed_url, '1.0', $header, $body);

      The write method has a fifth argument which is the $body; which will be the postfields.
      the $body will be the $postData for CURL

      curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

Leave a Comment

Your email address will not be published. Required fields are marked *