dongliang2005 2017-06-06 22:11
浏览 47
已采纳

如何在magento 1.9模块中使用cURL

I've developed a module, at the moment only some function and get/post from to Database , the front I have it already done. I want to add a class (cURL) to call 3rd party api, but I don't know how can I to implement that. It should be in controllers(IndexController?) or Model folder as new file? and if I have to add some details in config.xml?

  • 写回答

2条回答 默认 最新

  • doudao3170 2017-06-07 07:30
    关注

    There is no restriction to use the curl in a particular file. It depends on your module functionality and parameters. The most effective effort to use curl in indexcontroller. Use can create a function and initiate them.

    Example like:

      <?php
    
        $curl = new Varien_Http_Adapter_Curl();
        $curl->setConfig(array(
               'timeout'   => 15    //Timeout in no of seconds
        ));
        $feed_url = "http://feeds.feedburner.com/magento";
        $curl->write(Zend_Http_Client::GET, $feed_url, '1.0');
        $data = $curl->read();
        if ($data === false) {
           return false;
        }
        $data = preg_split('/^r?$/m', $data, 2);
        $data = trim($data[1]);
        $curl->close();
    
        try {
          $xml  = new SimpleXMLElement($data);
         //Parse the XML FEED and output the data
        }
        catch (Exception $e) {
           echo $e->getMessage();
        }
    
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?