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.

asked Feb 12, 2020 at 14:23

1 Answer 1

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.

answered Feb 12, 2020 at 15:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.