我刚刚安装了Fedora 19 LXDE。当我第一次为URL运行curl时,它失败了:

curl -v youtube.com
* Could not resolve host: youtube.com; Name or service not known
* Closing connection 0
curl: (6) Could not resolve host: youtube.com; Name or service not known

如果我立即重新运行此命令,它将成功。
curl -v youtube.com
* About to connect() to youtube.com port 80 (#0)
*   Trying 80.239.229.212...
* Connected to youtube.com (80.239.229.212) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: youtube.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Tue, 10 Sep 2013 20:05:20 GMT
< Server: gwiseguy/2.0
< Location: http://www.youtube.com/
< Content-Length: 0
< Content-Type: text/html
< X-XSS-Protection: 1; mode=block
<
* Connection #0 to host youtube.com left intact

看来,如果指定了-4选项,一切正常。可能是什么问题?

nslookup工作正常,分辨率没有问题。

更新:

当我对失败的尝试运行strace时,我看到以下错误:
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)

并回显$ LANG
LANG =/en_US.UTF-8
可以关联吗?

更多信息:
我曾经与Gnome一起使用Fedora 15。一切正常。然后,我尝试使用LXDE和XFCE的Fedora 19。他们两个都有相同的 curl 问题。

解析度:
似乎问题与IPv6有关。
1)创建内部带有“--ipv4”的〜/.curlrc。它解决了浏览器的一些问题。
2)要修复yum,请在/etc/yum.conf中添加“ip_resolve = 4”。

最佳答案

使用www.youtube.comyoutube.com

完整命令:

curl -v www.youtube.com

HTTP 301错误意味着页面已永久移动到新地址。在这种情况下,由服务器响应中的“位置”字段指示:



如果您不想为此担心,可以指定--location/-L标志,使其遵循HTTP重定向(301及其他),然后可以使用youtube.com:
curl -v -L youtube.com

关于linux - 第一次尝试后 curl 不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18748969/

10-16 23:45