1

有时我在尝试通过 curl 访问网页时遇到 404 错误,但如果我使用 file_get_contents 访问它工作的完全相同的 URL,知道为什么会这样吗?

这是一个示例:我的 curl 设置:

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 网络浏览器的请求标头:

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; --
4

0 回答 0