gpt4 book ai didi

linux - curl 从第一次尝试开始就不起作用

转载 作者:太空狗 更新时间:2023-10-29 12:18:18 32 4
gpt4 key购买 nike

我刚刚安装了 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有关系吗?

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

分辨率:
看来问题与 IPv6 有关。
1) 创建 ~/.curlrc 里面有“--ipv4”。它解决了一些浏览器的问题。
2) 要修复 yum,请将“ip_resolve=4”添加到/etc/yum.conf。

最佳答案

使用 www.youtube.comyoutube.com

完整命令:

curl -v www.youtube.com

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

Location: http://www.youtube.com/

如果你不想担心这个,你可以指定 --location/-L 标志,这样它将遵循 HTTP 重定向(301 和其他) 然后你可以使用 youtube.com:

curl -v -L youtube.com

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

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com