Cannot CURL remote file

I have a piece of code that is designed to retrieve any url and tear it out of the internet. While this works fine, until someone gave him this URL:

http://www.aspensurgical.com/static/images/aspen_hill-rom_logo.png

If I hit it from my browser, it shows that everything is fine. But when I try to curl it down, I get:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /static/images/aspen_hill-rom_logo.png
on this server.</p>
<hr>
<address>  Server at www.aspensurgical.com Port 80</address>
</body></html>

The CURL code I use:

$ch = curl_init(str_replace(' ', '%20', $url));
$fh = fopen($local_file, "w");
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_exec($ch);
curl_close($ch);

Is their server somehow realizing that I am not a normal browser and loading me?

+5
source share
2 answers

They have a user check to see who you are. Add a normal browser user interface and everything should be fine.

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");

Here's a working example in codepad .

+8
source

, , . , , curl -user-agent, !

Windows 7, gow.

curl --user-agent "Mozilla/4.0" http://www.example.com/archives/abc.txt --output pqr.txt
+1

All Articles