2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHP3.x系でHttp Client で通信をしようとしてSSL使いたくないよって言ったらハマったこと

Posted at

Cake3に用意されてるHttp Clientのクラスを使ってAPIとの通信をしようと考えていました。

設定はこんな感じで〜って言われて、
任せろみたいなことを言いました。

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

初めてだったのでここで見ながら書き換えて
PHP マニュアル cURL 関数
http://php.net/manual/ja/function.curl-setopt.php

こんな感じに書きました!(失敗作)

失敗

   $option = [
        'timeout'              => 5,
        'ssl_verify_peer'      => false,
        'ssl_verify_host' => false,
        'auth' => [
            'username' => 'username',
            'password' => 'password',
        ]
    ];
    $http = new Client($option);
    $url = 'ponpon.com';
    $request = ['animal'=>'tanuki'];
    $response = $http->post($url, $request, $option);

ずっとSSL通信でfopen(): Peer certificateってでる…これfalseしたでしょ…
なんでだろうってコード見に行ったら「ssl_verify_peer_name」がデフォルトでtrueになってました。

……「ssl_verify_peer」がfalseでも「ssl_verify_peer_name」はtrueに…そうか…わかった…
'ssl_verify_peer_name' => falseの記述増そう。。。

成功

   $option = [
        'timeout'              => 5,
        'ssl_verify_peer'      => false,
        'ssl_verify_peer_name' => false,
        'ssl_verify_host' => false,
        'auth' => [
            'username' => 'username',
            'password' => 'password',
        ]
    ];
    $http = new Client($option);
    $url = 'ponpon.com';
    $request = ['animal'=>'tanuki'];
    $response = $http->post($url, $request, $option);

これで動きました。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?