[英]“Content-Type” in header is not changing
I'm trying to call Rest web service with cURL that does next: 我正在尝试使用下一步执行的cURL调用Rest Web服务:
Every one of those functions is working alone, but when gathering them in one service the download dialog is not opening, and I'm always getting text/html as Content type, I saw it via Firebug. 这些功能中的每个功能都可以单独使用,但是当将它们收集到一项服务中时,下载对话框不会打开,并且我始终以text / html作为Content类型,这是通过Firebug看到的。
This is the code of the downloading (from php.ent): 这是下载代码(从php.ent):
if (file_exists($filename)) {
header("Content-Length: " . filesize($filename));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $certName);
readfile($filename, false);
exit();
}
and here's how I'm calling my service: 这是我给我的服务打电话的方式:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
$dat=array(
// many args
);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if ($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
} else {
echo "Data received: $data\n";
}
curl_close($ch);
What's wrong guys? 你们怎么了?
Data received: $data
as the body of an HTML document Data received: $data
作为HTML文档的正文 If you want the cURL using program to act as a proxy, then you need to proxy the HTTP headers and not add extra data to the output. 如果您希望使用程序的cURL充当代理,则需要代理HTTP标头,而不要在输出中添加额外的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.