1

I'm trying to get curl response from js (cc-method.js) file. The curl call code is in controller file domain.com/frontname/section/index. Below is the code,

public function execute()
    {
 // create a new cURL resource
                $ch = curl_init();

                $data = '{"merchantIdentifier":"'.PRODUCTION_MERCHANTIDENTIFIER.'", "domainName":"'.PRODUCTION_DOMAINNAME.'", "displayName":"'.PRODUCTION_DISPLAYNAME.'"}';

                curl_setopt($ch, CURLOPT_URL, $validation_url);
                curl_setopt($ch, CURLOPT_SSLCERT, PRODUCTION_CERTIFICATE_PATH);
                curl_setopt($ch, CURLOPT_SSLKEY, PRODUCTION_CERTIFICATE_KEY);
                curl_setopt($ch, CURLOPT_SSLKEYPASSWD, PRODUCTION_CERTIFICATE_KEY_PASS);
                //curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
                //curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1_2');
                //curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'rsa_aes_128_gcm_sha_256,ecdhe_rsa_aes_128_gcm_sha_256');
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $result = curl_exec($ch);
                curl_close($ch);

                // close cURL resource, and free up system resources

                return $result;
}

I'm getting the response but with error too. Below is the response,

{"epochTimestamp":1581515057355,"expiresAt":1581518657355,"merchantSe .........................

error:

Exception: Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/........Index.php

It is pointing the line of $result = curl_exec($ch);.

I have tried to disable the php error and warning but that time there is no response. The response always coming with error only. Any hint will be helpfull for me.

2

By default curl_exec will print the response, that's causing the output started error when you return the content.

Try to add curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl option. This will store the result in your $result var.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.