zoukankan      html  css  js  c++  java
  • Magento2 中如何使用curl

    $ url =>包含端点网址。$ params =>它是一个数组,如果你想在url附加额外的参数。$ response =>它将包含json形式的输出。
     
    代码:
    /**
     * @var MagentoFrameworkHTTPClientCurl
     */
    protected $_curl;
     
    /**
     * @param Context                             $context
     * @param MagentoFrameworkHTTPClientCurl $curl
     */
    public function __construct(
        Context $context,
        MagentoFrameworkHTTPClientCurl $curl
    ) {
        $this->_curl = $curl;
        parent::__construct($context);
    }
     
    public function execute()
    {
        //if the method is get
        $this->_curl->get($url);
        //if the method is post
        $this->_curl->post($url, $params);
        //response will contain the output in form of JSON string
        $response = $this->_curl->getBody();
    }
  • 相关阅读:
    apt-get
    微博
    字符串操作
    fly
    Oracle数据库只Dual表
    如何配置一个Oracle服务
    排序算法
    排序算法
    排序算法
    ArcEngine几个空间操作
  • 原文地址:https://www.cnblogs.com/shenlongjue/p/7525097.html
Copyright © 2011-2022 走看看