curl - How do I download a file from an .ashx page with php? -


i trying download file url in php: http://www.roblox.com/asset/bodycolors.ashx?userid=36377783

the page returns file webbrowser automatically downloads.

i tried using curl:

<?php $uid = 36377783;  $xurl = "http://www.roblox.com/asset/bodycolors.ashx?userid=".$uid;  $ch = curl_init(); curl_setopt($ch, curlopt_url, $xurl); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_header, false); curl_setopt($ch, curlopt_ssl_verifyhost, false); $xml = curl_exec($ch); curl_close($ch);  echo $xml;  ?> 

but redirects me error page.

how download file .ashx url returns?

(setting curlopt_useragent doesn't work.)

there redirection - use file_get_contents() (but why not curl) , $http_response_header:

$uid = 36377783;  $xurl = "http://www.roblox.com/asset/bodycolors.ashx?userid=".$uid;  $opts = array(   'http'=>array(       'method'=>"get",       'follow_location' => true,       'header'=>         "host: www.roblox.com\r\n" .         "user-agent: mozilla/5.0 (windows nt 6.1; wow64; rv:43.0) gecko/20100101 firefox/43.0\r\n" .         "accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" .         "accept-encoding: gzip, deflate\r\n" .         "dnt: 1\r\n"    ) );   $context = stream_context_create($opts); $xml = file_get_contents($xurl, false, $context); #print_r($http_response_header); $url_redirect = str_replace('location: ',"",$http_response_header[5]); #print $url_redirect; $xml = file_get_contents($url_redirect); #print_r($xml); $roblox_responses = new simplexmlelement($xml); print_r($roblox_responses); 

Comments