[英]“Content-Type” in header is not changing
我正在嘗試使用下一步執行的cURL調用Rest Web服務:
這些功能中的每個功能都可以單獨使用,但是當將它們收集到一項服務中時,下載對話框不會打開,並且我始終以text / html作為Content類型,這是通過Firebug看到的。
這是下載代碼(從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();
}
這是我給我的服務打電話的方式:
$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);
你們怎么了?
Data received: $data
作為HTML文檔的正文 如果您希望使用程序的cURL充當代理,則需要代理HTTP標頭,而不要在輸出中添加額外的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.