【问题标题】:301 curl does not show without -v301 curl 不显示没有 -v
【发布时间】:2014-12-08 07:11:24
【问题描述】:

我正在查看几个 2.level 域用于重定向到其 www 3.level 域的 301,我认为 curl 本身就足够了,例如

curl  myvote.io
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.myvote.io/">here</A>.
</BODY></HTML>

但是,我不得不使用 curl -v 来获取另一个域上的任何输出:

curl -v evitaochel.com
* Rebuilt URL to: evitaochel.com/
* Hostname was NOT found in DNS cache
*   Trying 62.116.130.8...
* Connected to evitaochel.com (62.116.130.8) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: evitaochel.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Mon, 13 Oct 2014 16:18:02 GMT
* Server Apache is not blacklisted
< Server: Apache
< Location: http://www.evitaochel.com
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8 
<
* Connection #0 to host evitaochel.com left intact

如果有的话,我原以为 myvote.io 会更奇怪,

curl -v myvore.io
* Rebuilt URL to: myvote.io/
* Hostname was NOT found in DNS cache
*   Trying 216.239.36.21...
* Connected to myvote.io (216.239.36.21) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: myvote.io
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Location: http://www.myvote.io/
< Date: Mon, 13 Oct 2014 16:30:40 GMT
< Content-Type: text/html; charset=UTF-8
* Server ghs is not blacklisted
< Server: ghs
< Content-Length: 218
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< Alternate-Protocol: 80:quic,p=0.01
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.myvote.io/">here</A>.
</BODY></HTML>
* Connection #0 to host myvote.io left intact

显示它包含一些扩展并且由 ghs 提供服务,我猜是 Google。任何想法可能是什么原因,如果原因在“curl -v”中总是可见的或者可能是一些隐藏的配置?

【问题讨论】:

    标签: redirect curl http-status-code-301


    【解决方案1】:

    curl 在没有任何选项的情况下使用时不会显示任何响应标头,这就是它的工作原理。使用-v 甚至-i 只能查看标题。

    重定向页面(301、302 或其他)可能包含正文,但也可能不包含。这取决于网站。

    由于您获得了 HTTP 重定向,您可能还想使用 -L 来让 curl 跟随它们。

    【讨论】:

    • 重点是我想查看重定向,尤其是发现它是 301 或 302。所以,您是说 myvote.io 选择在 HTML 中包含 301 消息,而 evitaochel.com选择不这样做,也没有约定?
    • 正是如此。重定向“页面”也可以包含 HTML(正文)或不包含,这由站点决定。您可以轻松使用 curl 的 -w 输出 HTTP 响应代码。
    【解决方案2】:

    在使用 curl 测试重定向时,我使用 --head。使用此标志会导致 curl 发出不包含文档且不遵循重定向的特殊类型的 HTTP 请求。然后 curl 显示 HTTP 标头。

    来自the manual

    仅获取标题! HTTP 服务器具有 HEAD 命令,该命令用于获取文档标题以外的任何内容。

    $ curl --head http://myvote.io/
    HTTP/1.1 302 Found
    Location: https://myvote.io/
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-11
      • 2017-08-13
      • 2021-12-03
      • 1970-01-01
      • 2019-02-05
      • 2018-11-08
      • 1970-01-01
      • 2021-04-30
      相关资源
      最近更新 更多