301 curl does not show without -v

27,395

curl doesn't show any response headers when used without any option, that's just how it works. Use -v or even -i to get to see the headers only.

A redirect page (301, 302 or whatever) MAY contain a body but it also MAY NOT. That is up to the site.

Since you get HTTP redirects, you may want to use -L too to make curl follow them.

Share:
27,395
fidetrainerNET
Author by

fidetrainerNET

Updated on July 09, 2022

Comments

  • fidetrainerNET
    fidetrainerNET almost 2 years

    I was looking at the 301s that several 2.level domains use to redirect to their www 3.level domain, and I thought curl on its own was enough, for example

    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>
    

    However, I had to use curl -v to get any output on another domain :

    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
    

    If anything, I was expecting myvote.io to be the weirder one,

    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
    

    shows that it includes some extensions and is served by ghs, Google I guess. Any ideas what could be the cause, and if the cause is always visible in "curl -v" or could be some hidden configuration?

  • fidetrainerNET
    fidetrainerNET over 9 years
    the whole point is I want to see the redirect, especially find out it is 301 or 302. So, you are saying that myvote.io chose to include a 301 message in HTML, while evitaochel.com chose not to, and there is no convention dictating either?
  • Daniel Stenberg
    Daniel Stenberg over 9 years
    Exactly so. A redirect "page" can also contain HTML (a body) or not, that's up to the site to decide. You can easily use curl's -w to output the HTTP response code.