无论我指定什么 URL,curl
我总是得到相同的 HTML 404 错误页面。
如果我使用该--verbose
选项,它看起来curl
总是连接到同一个 IP 地址。
$ curl --verbose http://www.edgeoftheweb.co.uk
* About to connect() to www.edgeoftheweb.co.uk port 80
* Trying ::ffff:74.117.222.24... connected
* Connected to www.edgeoftheweb.co.uk (::ffff:74.117.222.24) port 80
> GET / HTTP/1.1
> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: www.edgeoftheweb.co.uk
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 15 Sep 2011 13:52:07 GMT
< Server: Apache/2.2.3 (CentOS)
< X-Powered-By: PHP/5.2.11
< Content-Length: 519
< Connection: close
< Content-Type: text/html; charset=UTF-8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>www.edgeoftheweb.co.uk</TITLE>
</HEAD>
<FRAMESET rows="100%,*" border="0" frameborder="0" framespacing="0">
<FRAME name=top src="http://www.searchnut.com/?domain=edgeoftheweb.co.uk®istrar=directnicexpired&aff_txt=This+domain+is+expired%2C+please+renew+it.&aff_url=https%3A%2F%2Fsecure.directnic.com%2Fmyaccount%2Frenewals%2F" noresize>
</FRAMESET>
Closing connection #0
$ curl --verbose http://api.twitter.com
* About to connect() to api.twitter.com port 80
* Trying ::ffff:74.117.222.24... connected
* Connected to api.twitter.com (::ffff:74.117.222.24) port 80
> GET / HTTP/1.1
> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: api.twitter.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 15 Sep 2011 13:53:25 GMT
< Server: Apache/2.2.3 (CentOS)
< X-Powered-By: PHP/5.2.11
< Content-Length: 505
< Connection: close
< Content-Type: text/html; charset=UTF-8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>api.twitter.com</TITLE>
</HEAD>
<FRAMESET rows="100%,*" border="0" frameborder="0" framespacing="0">
<FRAME name=top src="http://www.searchnut.com/?domain=twitter.com®istrar=directnicexpired&aff_txt=This+domain+is+expired%2C+please+renew+it.&aff_url=https%3A%2F%2Fsecure.directnic.com%2Fmyaccount%2Frenewals%2F" noresize>
</FRAMESET>
Closing connection #0
的输出curl --version
为:
curl 7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Protocols: tftp ftp telnet dict ldap http file https ftps
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
如果我改用wget
,那么我会检索正确的页面。
有什么想法可以curl
正确解析 URL 吗?谢谢。
答案1
* Connected to www.edgeoftheweb.co.uk (::ffff:74.117.222.24) port 80
* Connected to api.twitter.com (::ffff:74.117.222.24) port 80
在我看来 curl 使用 ipv6 进行连接,而 wget 使用 ipv4
尝试以下操作
curl --verbose -4 http://api.twitter.com
答案2
这有点不切实际,但请尝试暂时将您的名称服务器更改为 Google 的 DNS 服务器:
8.8.8.8
8.8.4.4
看起来,libcurl 无法解析这些 DNS 名称,但您的 ISP 的 DNS 服务器没有返回正确的 DNS 响应 (NXDOMAIN),而是返回搜索结果。我不知道为什么 wget 的响应会有显著差异,但至少您可能希望 ISP 的服务器妨碍您的故障排除。