phpのcurlでsslサイトにつなぐ

phpからcurlを使ってサイトにアクセスした際に
どうしてもレスポンスが取得できないことが発生。

何もレスポンスがないので原因判明に苦労したが
terminalのコマンドで

curl -I https://example.com -k

と入力すると

curl: (35) Unknown SSL protocol error in connection to example:443

ということでSSLのプロトコルエラーであることが判明。

色々とコマンドを試し、

curl -I https://example.com -k  --tlsv1

で接続できた。

これをphpのcurlでどうやるかも苦労したけど
下記のオプションで、SSLのバージョンを手動指定することで解決。

curl_setopt_array($m,
  array(
    CURLOPT_URL =>'https://example.com',
    CURLOPT_SSLVERSION => 1,
  )   
);

SSLのバージョンは通常、自動判別するけど
サイトによってはそれが上手く動かず
指定をする必要があるみたい。

You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

1 Comment »

 
 

コメントを残す

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

CAPTCHA