简体   繁体   中英

grab file from php which forced to save as from another web server php with http authentication

  1. i have a url from another server which having http auth enabled.
  2. this specific url forces file to download a file.
  3. 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 did not gave any error. nothing returned in $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. just used urlencode and code working fine now. Hope this will help someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM