简体   繁体   中英

CURL CURLOPT_RETURNTRANSFER in conflict with CURLOPT_HEADER

When I use both parameters in my 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. Only problem here is that the header isn't provided.

When I remove CURLOPT_RETURNTRANSFER , I get the full string (header and body). 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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