1 分钟

Magento2 Zend_Http_Client 使用 http_proxy代理

开发中,如果遇到某种特殊情况下,无法访问外网,则可以设置代理

//file vendor/magento/framework/HTTP/Adapter/Curl.php after line 26
    /**
    * Parameters array
    *
    * @var array
    */
protected $_config = [
    'protocols' => (CURLPROTO_HTTP
        | CURLPROTO_HTTPS
        | CURLPROTO_FTP
        | CURLPROTO_FTPS
    ),
    'verifypeer' => true,
    'verifyhost' => 2,
    'proxy' => "http://127.0.0.1:8888"//add http proxy here
];
//file vendor/magento/zendframework1/library/Zend/Http/Client.php after line 1089
$response = $this->adapter->read();
//remove extra response afteradd proxy
if (false !== stripos($response, "HTTP/1.1 200 Connection established\r\n\r\n")) {
    $response = str_ireplace("HTTP/1.1 200 Connection established\r\n\r\n", '', $response);
}

转载请注明出处:http://www.jiliuke.com/2021/07/16/magento2-Zend-Http-Client-use-proxy/