这是我的密码
$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';所有这些都在一个控制器中,该控制器在ajax调用时被调用。但是,当我在jQuerysuccess处理程序上执行console.log(data)时,我得到的是完全响应,这个响应是由curl请求发送的,并且"hello“也附加到该响应中。我不知道回复是怎么发出的。
发布于 2020-01-01 20:58:22
您丢失了curl呼叫的CURLOPT_RETURNTRANSFER选项。否则,curl_exec将不会将调用的响应作为字符串返回,而是直接输出它。来自手册 for CURLOPT_RETURNTRANSFER
若要将传输作为curl_exec()返回值的字符串返回,而不是直接输出,则为TRUE。
所以,加上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);应该将输出正确地返回到$result变量中。
https://stackoverflow.com/questions/59555818
复制相似问题