How to get data from a website that uses SSL using cURL and PHP?

后端 未结 2 1458
北荒
北荒 2021-01-28 06:38

I am trying to get some data from a website where you need to have a SSL certificate to be able to connect to it. I have found the following code :

// create curl         


        
相关标签:
2条回答
  • 2021-01-28 06:58

    Try this.

    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://jsonplaceholder.typicode.com/todos/1",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",
        CURLOPT_HTTPHEADER => array("content-type: application/json"),
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
        echo "cURL Error #:" . $err;
    } else {
        echo $response;
    }
    
    0 讨论(0)
  • 2021-01-28 06:59

    can you try like this? echo $str = file_get_contents("https://jsonplaceholder.typicode.com/todos/1");

    0 讨论(0)
提交回复
热议问题