[英]grab file from php which forced to save as from another web server php with http authentication
I am trying here to grab the headers and set the headers back so that i can force the download from my php file after http auth done in curl, but no success. 我在这里尝试抓住标头并将标头设置回去,以便我可以在curl中完成http auth后强制从我的php文件下载文件,但没有成功。 curl did not gave any error.
curl没有给出任何错误。 nothing returned in $body.
$ 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;
code above is working fine. 上面的代码工作正常。 Issue is just & in the $_GET["url"] which splitting valid url.
问题只是&在$ _GET [“ url”]中分割有效的URL。 just used urlencode and code working fine now.
刚刚使用了urlencode ,现在代码工作正常。 Hope this will help someone.
希望这会帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.