Welcome Guest, Not a member yet? Register   Sign In
set up rest with https

(This post was last modified: 08-02-2018, 04:47 AM by anthos1984.)

I have set up REST server support https using my own generated certificate.

Then I have the client POSTing data using https. But it seems not work. When using http it works. Here the code

PHP Code:
case "POST"// Used to create a new object on the server (INSERT)
    if($data === NULL){
        return FALSE;
    } else {
       $fields_string "";
       foreach($data as $key=>$value){
            $fields_string .= $key.'='.$value.'&';
       $fields_string rtrim($fields_string,'&');
       $ch curl_init($url);
       if($scheme == 'https'){
            $cert config_item('cert_path');
       $rdata curl_exec($ch);
       $this->responseCode curl_getinfo($ch,CURLINFO_RESPONSE_CODE);

I'm sure config_item('cert_path') points to certificate file downloaded from server

Tell me if I'm wrong setting up curl.
Also, how to know if my clients certificate rejected by server? Is CI reports it in log (server) or log (client)?

make a var_dump on $rdata for error messages.
cert_path should be a local path to a .pem file.

i do log_message('debug', var_export($rdata, TRUE));
The result is 'false'
No messages Sad

Ok, you got an error then.

Use curl_error to see what:

OK, done. Thanks..
So is use curl_error($ch) to see.
I'm using CI4, so i set cert path in .env : app.CertPath = APPPATH.'Cert/livehost.crt'
and in the code : curl_setopt($ch, CURLOPT_CAINFO, $config->CertPath);
But unfortunately APPPATH not work on .env,
curl error says "error setting certificate verify locations" and show plain APPPATH !!
It should be changed with 'something/application'

So I change on .env : app.CertPath = 'application/Cert/livehost.crt'
and in the code :
curl_setopt($ch, CURLOPT_CAINFO, ROOTPATH.$config->CertPath);

I haven't tried CI4, so can't give you any feedback on why that's not working. But at least you can hardcode it for now.

Theme © iAndrew 2016 - Forum software by © MyBB