[英]grab file from php which forced to save as from another web server php with http authentication
我在這里嘗試抓住標頭並將標頭設置回去,以便我可以在curl中完成http auth后強制從我的php文件下載文件,但沒有成功。 curl沒有給出任何錯誤。 $ body中什么也沒有返回。
$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;
上面的代碼工作正常。 問題只是&在$ _GET [“ url”]中分割有效的URL。 剛剛使用了urlencode ,現在代碼工作正常。 希望這會幫助某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.