简体   繁体   中英

Equivalent of a CURL command with certificates in PHP

I'm need to know how to write the follow CURL command in PHP, I tried it from various modes and I searched in many articles here in the StackOverflow and I tried to adaptate the code but nothing is really working:

curl -v --insecure --cert public-certified-with-chain.pem --key private-key.key -nodes GET "MY_URL" "accept: */*"

I managed to reach this stage, but it doesn't work:

   $ch = curl_init();

   curl_setopt($ch, CURLOPT_URL, 'https://...');
   curl_setopt($ch, CURLOPT_VERBOSE, 1);

   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);

   $result = curl_exec($ch);

   echo $result;

The code above is simplified, it return a result, but still showing "Unauthorized".

How to adapt it to attach the files?

curl's --cert option corresponds to CURLOPT_SSLCERT , which isn't present in your PHP code.

I suggest you add --libcurl sample.c to your command line to get a code template (in C), that you then can translate to PHP.

Also, the command line shown in the question doesn't appear to be a fully working curl command line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM