PHP's cURL: How to connect over HTTPS?

前端 未结 5 1287
余生分开走
余生分开走 2021-02-15 12:23

I need to do a simple GET request to EC2 Query API with regular URL encoded query string. The protocol is HTTPS. How would I send the request with the help of PHP\'s cURL.

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-15 12:51

    Example:

    $url = "https://example.com";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
    
    $result = curl_exec($ch);
    curl_close($ch);
    
    print_r($result);
    

    CURLOPT_SSL_VERIFYPEER

    Check if peer certificate is valid or invalid/expired.

    CURLOPT_SSL_VERIFYHOST quoting from php manual:

    1 to check the existence of a common name in the SSL peer certificate. 2 to check the existence of a common name and also verify that it matches the hostname provided.

提交回复
热议问题