0
- 我有一個URL從另一臺服務器啓用HTTP身份驗證。
- 這個特定的url強制文件下載一個文件。
我想在這裏抓住標題並設置標題,以便在curl完成http auth後強制從我的php文件下載,但沒有成功。捲曲沒有給出任何錯誤。 $ body中沒有返回。從php強制保存爲從另一個網絡服務器PHP與http認證保存文件
$url=$_GET["url"];//another web server url which forcing file download save as $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_USERPWD, "username:password");//http auth done here curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, null); curl_setopt($ch, CURLOPT_URL, $url); $response = curl_exec($ch); list ($headerString, $body) = explode("\r\n\r\n", $response, 2); $headers = explode("\r\n", $headerString); foreach ($headers as $header) { header($header); } echo $body; exit;
請您重新說明步驟2和3。我沒有得到你想要做的。還請更具體地說「不成功」 - 任何錯誤消息? 'curl_error()'輸出? – nem75