curl參數設定的問題 有關CURLOPT_SSL_VERIFYHOST

來源:互聯網
上載者:User
PHP Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead in 

這裡就是把

curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, true );

改成

curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, 2 );

就可以了嗎?

回複內容:

PHP Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead in 

這裡就是把

curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, true );

改成

curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, 2 );

就可以了嗎?

是的

CURLOPT_SSL_VERIFYHOST的值

  • 設為0表示不檢查認證
  • 設為1表示檢查認證中是否有CN(common name)欄位
  • 設為2表示在1的基礎上校正當前的網域名稱是否與CN匹配

libcurl早期版本中這個變數是boolean值,為true時作用同目前設定為2,後來出於調試需求,增加了僅校正是否有CN欄位的選項,因此兩個值true/false就不夠用了,升級為0/1/2三個值。

再後來(libcurl_7.28.1之後的版本),這個調試選項由於經常被開發人員用錯,被去掉了,因此目前也不支援1了,只有0/2兩種取值。

引自 libcurl API

When the verify value is 1, curl_easy_setopt will return an error and
the option value will not be changed. It was previously (in 7.28.0 and
earlier) a debug option of some sorts, but it is no longer supported
due to frequently leading to programmer mistakes. Future versions will
stop returning an error for 1 and just treat 1 and 2 the same.

最新版本,它的預設值就是2,因此,這行代碼,可以省略不寫。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.