1) You forgot to translate --user
option. Its counterpart in PHP libcurl is CURLOPT_USERPWD
option.
2) As has already written in the comments you have to disable SSL peer verification by setting CURLOPT_SSL_VERIFYPEER
option to false
.
3) You shouldn't set CURLOPT_CUSTOMREQUEST
and CURLOPT_POST
options together, only one of them (CURLOPT_POST
in your case).
So the code should look like this:
...
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERPWD => 'username/password',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data_string,
CURLOPT_HTTPHEADER => array(
'Content-Type:application/json',
'Content-Length: ' . strlen($data_string)
),
));
$result = curl_exec($ch);
var_dump($result);