A
A
Alyosha2018-02-13 19:51:06
PHP
Alyosha, 2018-02-13 19:51:06

How to use CURL for secure connections? SSL?

I want to connect to the site via CURL, what should I do to make curl work with https? Everything works, but only on http.
Example of my code:
<?PHP
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => ' https://mysite ',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_REFERER => ' https:// mysite ',
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_USERPWD => "mylogin:mypass",
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
CURLOPT_FAILONERROR => false,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => [
'row'=>'data'
]
]);

$res = curl_exec($curl);
echo $res;
curl_close($curl);
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2018-02-13
@dimonchik2013

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
just
test here

O
Oleg, 2018-02-14
@402d

php.ini
curl.cainfo =
you can take pem itself https://curl.haxx.se/docs/caextract.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question