Here is my code
$url = 'https://'.$_ENV["MAIL_CHIMP_DC"] .'.api.mailchimp.com/3.0/lists/'.$_ENV["MAIL_CHIMP_LIST_ID"].'/members';
error_log('url-mail_chimp');
error_log($url);
$authorization_header=base64_encode('anystring:'.$_ENV['MAIL_CHIMP_API_KEY']);
error_log($authorization_header);
$ch=curl_init($url);
$data_string = $data;
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Basic '.$authorization_header));
$result =curl_exec($ch);
error_log($result);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
error_log($httpcode);
curl_close($ch);
echo 'hello';
This is all inside a controller which is being called on ajax call. But when I am doing console.log(data)
on jquery success
handler, I am getting full response which is being sent over by curl request and also "hello" is appended to that response. I don't know how the response is being sent.