- i have a url from another server which having http auth enabled.
- this specific url forces file to download a file.
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;
Asked
Active
Viewed 445 times
0

jit
- 1,616
- 3
- 21
- 49
-
Could you please rephrase step 2. and 3.? I don't get what you are trying to do. Also please be more specific about "no success" - any error messages? `curl_error()` output? – nem75 May 30 '12 at 09:37
1 Answers
0
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.

jit
- 1,616
- 3
- 21
- 49