簡體   English   中英

在 Zend_HTTP_Client 中跳過 SSL 檢查

[英]Skip SSL Check in Zend_HTTP_Client

我正在使用 Zend_HTTP_Client 向服務器發送 HTTP 請求並獲得響應。 我向其發送請求的服務器是 HTTPS Web 服務器。 目前,一個往返請求大約需要 10-12 秒。 我知道開銷可能是因為請求到達的 Web 服務器的處理速度很慢。

是否可以像我們在 CURL 中那樣跳過 SSL 證書檢查以提高性能? 如果是這樣,如何設置這些參數?

我有以下代碼:

    try
    {
        $desturl ="https://1.2.3.4/api";

        // Instantiate our client object
        $http = new Zend_Http_Client();

        // Set the URI to a POST data processor
        $http->setUri($desturl);

        // Set the POST Data
        $http->setRawData($postdata);

        //Set Config
        $http->setConfig(array('persistent'=>true));

        // Make the HTTP POST request and save the HTTP response
        $httpResponse = $http->request('POST');
    }
    catch (Zend_Exception $e)
    {
        $httpResponse = "";
    }

    if($httpResponse!="")
    {
        $httpResponse = $httpResponse->getBody();
    }

    //Return the body of HTTTP Response
    return  $httpResponse;

如果您確信SSL是問題所在,那么您可以將Zend_Http_Client配置為使用curl ,然后傳入適當的curl選項。

http://framework.zend.com/manual/en/zend.http.client.adapters.html

$config = array(  
    'adapter'   => 'Zend_Http_Client_Adapter_Curl',  
    'curloptions' => array(CURLOPT_SSL_VERIFYPEER => false),  
); 

$client = new Zend_Http_Client($uri, $config);

我實際上推薦使用curl適配器,因為curl幾乎具有您需要的所有選項,而且Zend確實提供了一個非常好的包裝器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM