PHP Curl在加载图像时有时会出现404错误,但它与file_get_contents()有效,为什么会这样?

时间:2012-06-20 13:55:44

标签: php curl header

有时我在尝试通过curl访问网页时遇到404错误,但是如果我使用file_get_contents来访问它运行的完全相同的网址,那么任何想法为什么会这样?

这是一个例子: 我的卷曲设置:

curl_setopt($this->ch, CURLOPT_USERAGENT, $this->UserAgent);
curl_setopt($this->ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->CookieFile);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->CookieFile);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->ch,CURLOPT_VERBOSE,true);
curl_setopt($this->ch,CURLOPT_HEADER,true);
curl_setopt($this->ch,CURLOPT_ENCODING, "gzip");
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 30);

我的firefox webbrowser的请求标头:

GET /image.png HTTP/1.1
Host: ssl.website.net
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: some cookie info
Cache-Control: max-age=0

响应标题:

HTTP/1.1 200 OK
Date: Wed, 20 Jun 2012 13:38:43 GMT
Content-Type: image/png
Transfer-Encoding: chunked
Connection: close
Pragma: no-cache
Cache-Control: no-cache
Server: '; DROP TABLE servertypes; --

0 个答案:

没有答案