简体   繁体   English

CURL CURLOPT_RETURNTRANSFER与CURLOPT_HEADER冲突

[英]CURL CURLOPT_RETURNTRANSFER in conflict with CURLOPT_HEADER

When I use both parameters in my curl: 当我在curl中使用两个参数时:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) and
curl_setopt($ch, CURLOPT_HEADER, TRUE)

I receive an empty data back. 我收到一个空数据。

Any idea why? 知道为什么吗?

When I remove CURLOPT_HEADER , I have my response where I can convert to array. 当我删除CURLOPT_HEADER ,我有我的响应,我可以转换为数组。 Only problem here is that the header isn't provided. 这里唯一的问题是没有提供标头。

When I remove CURLOPT_RETURNTRANSFER , I get the full string (header and body). 当我删除CURLOPT_RETURNTRANSFER ,我得到完整的字符串(标题和正文)。 The only problem here is that it prints directly and I'm not able to convert it to an array. 这里唯一的问题是它直接打印,我无法将其转换为数组。

Someone who has an idea? 有想法的人?

try this 尝试这个

curl_setopt($ch, CURLOPT_URL, 'http://localhost/api/upload.php');
curl_setopt($ch, CURLOPT_HTTPHEADER,true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM