0

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 resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, $host);

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $host);

// $output contains the output string
$output = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch);

The cURL query works well, but the data that I get is this one :

400 No required SSL certificate was sent

400 Bad Request

No required SSL certificate was sent
nginx

What I am looking for is the data contained in the index.php (and the other paths) of the website. So, how can I do to add a Certificate to the code, and, using cURL, get the data from the website ? PS : Will the data will be in JSON format ? PPS : if this can be helpfull, I am using PHPStorm

edode
  • 43
  • 5

2 Answers2

0

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;
}
  • hello, at first, I am always trying to understand the code before using it, so I have a question : what is "jsonplaceholder.typicode.com" ? – edode Jan 04 '21 at 13:41
  • @edoode Just go to that website and see: [http://jsonplaceholder.typicode.com/](http://jsonplaceholder.typicode.com/): "{JSON} Placeholder -- Free to use fake online REST API for testing and prototyping." – LazyOne Jan 04 '21 at 14:18
  • I end with the same error, I added the certificate in PhpStorm but it doesn't seem to help – edode Jan 06 '21 at 09:59
0

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

Nathan
  • 1
  • 2