Unix 为什么curl会在输出中重复标题?

Unix 为什么curl会在输出中重复标题?,unix,curl,Unix,Curl,我使用的选项: -I, --head (HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document. When used on an FTP or FILE file, curl displays the file siz

我使用的选项:

-I, --head
      (HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature
      the  command  HEAD which this uses to get nothing but the header
      of a document. When used on an FTP or FILE file,  curl  displays
      the file size and last modification time only.

-L, --location
      (HTTP/HTTPS)  If the server reports that the requested page has moved to a different location (indi-
      cated with a Location: header and a 3XX response code), this option will make curl redo the  request
      on  the  new  place.  If  used together with -i, --include or -I, --head, headers from all requested
      pages will be shown. When authentication is used, curl only sends its  credentials  to  the  initial
      host. If a redirect takes curl to a different host, it won't be able to intercept the user+password.
      See also --location-trusted on how to change this. You can limit the amount of redirects  to  follow
      by using the --max-redirs option.

      When  curl  follows a redirect and the request is not a plain GET (for example POST or PUT), it will
      do the following request with a GET if the HTTP response was 301, 302, or 303. If the response  code
      was any other 3xx code, curl will re-send the following request using the same unmodified method.

      You  can tell curl to not change the non-GET request method to GET after a 30x response by using the
      dedicated options for that: --post301, --post302 and -post303.

-v, --verbose
      Be more verbose/talkative during the operation. Useful for debugging  and  seeing  what's  going  on
      "under the hood". A line starting with '>' means "header data" sent by curl, '<' means "header data"
      received by curl that is hidden in normal cases, and a line starting with '*' means additional  info
      provided by curl.

      Note  that  if  you  only  want HTTP headers in the output, -i, --include might be the option you're
      looking for.

      If you think this option still doesn't give you enough details, consider using --trace  or  --trace-
      ascii instead.

      This option overrides previous uses of --trace-ascii or --trace.

      Use -s, --silent to make curl quiet.
-I,--head
(HTTP/FTP/FILE)仅获取HTTP头!HTTP服务器功能
它使用的命令头只获取头
文件的名称。在FTP或文件上使用时,将显示curl
仅显示文件大小和上次修改时间。
-五十、 --位置
(HTTP/HTTPS)如果服务器报告请求的页面已移动到其他位置(indi-
使用Location:header和3XX响应代码),此选项将使curl重做请求
在新的地方。如果与-i、-include或-i、-head一起使用,则所有请求的
页面将显示。使用身份验证时,curl只将其凭据发送给初始用户
主办如果重定向将curl转移到其他主机,它将无法截获用户+密码。
另请参见--location trusted,了解如何更改此设置。您可以限制要遵循的重定向数量
通过使用--max redirs选项。
当curl跟随重定向,并且请求不是普通的GET(例如POST或PUT)时,它将
如果HTTP响应是301、302或303,则使用GET执行以下请求。如果响应代码
如果是任何其他3xx代码,curl将使用相同的未修改方法重新发送以下请求。
通过使用
专用选项:--post301、-post302和-post303。
-v、 --冗长
在操作过程中更详细/更健谈。用于调试和查看正在进行的操作
“引擎盖下”。以“>”开头的一行表示curl发送的“标题数据”,主机:www.mail.com
>用户代理:curl/7.43.0
>接受:*/*
> 
HEAD/HTTP/1.1
>主持人:www.mail.com
>用户代理:curl/7.43.0
>接受:*/*
> 
使用:

curl-ILvhttp://www.mail.com 2> &1| grep'^[\*].$'
当使用verbose命令行标志调用cURL时,它会将详细输出发送到stderr而不是stdout。上面的命令将stderr重定向到stdout(2>&1),然后我们将合并的输出通过管道传输到grep,并使用上面的正则表达式仅返回以*开头的行。将从输出中删除输出中的所有其他行(包括您首先关注的复制品)。

使用:

curl-ILvhttp://www.mail.com 2> &1| grep'^[\*].$'

当使用verbose命令行标志调用cURL时,它会将详细输出发送到stderr而不是stdout。上面的命令将stderr重定向到stdout(2>&1),然后我们将合并的输出通过管道传输到grep,并使用上面的正则表达式仅返回以*开头的行。输出中的所有其他行(包括您首先关注的复制)都将从输出中删除。

最佳猜测:使用-v,您告诉curl要详细(发送调试信息)到STDERR。使用-I命令curl将头转储到STDOUT。默认情况下,您的shell将结合STDOUT和STDERR。将stdout和stderr分开,可以避免混淆


curl-ILvhttp://www.mail.com >stdout.log 2>stderr.log;cat stdout.log

最佳猜测:使用-v命令curl向STDERR发送详细的调试信息。使用-I命令curl将头转储到STDOUT。默认情况下,您的shell将结合STDOUT和STDERR。将stdout和stderr分开,可以避免混淆


curl-ILvhttp://www.mail.com >stdout.log 2>stderr.log;cat stdout.log

省略
-v
选项的问题是curl不显示请求,它只显示响应。我还需要查看请求。请参见上面对我原始答案的编辑。这会让你到达你想要到达的地方。cURL-v向stderr发送输出并不明显,所以我只是将stderr重定向到stdout
$ curl -ILv http://www.mail.com

* Rebuilt URL to: http://www.mail.com/
*   Trying 74.208.122.4...
* Connected to www.mail.com (74.208.122.4) port 80 (#0)
> HEAD / HTTP/1.1
> Host: www.mail.com
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
< Date: Sun, 28 May 2017 22:02:16 GMT
Date: Sun, 28 May 2017 22:02:16 GMT
< Server: Apache
Server: Apache
< Location: https://www.mail.com/
Location: https://www.mail.com/
< Vary: Accept-Encoding
Vary: Accept-Encoding
< Connection: close
Connection: close
< Content-Type: text/html; charset=iso-8859-1
Content-Type: text/html; charset=iso-8859-1

< 
* Closing connection 0
* Issue another request to this URL: 'https://www.mail.com/'
*   Trying 74.208.122.4...
* Connected to www.mail.com (74.208.122.4) port 443 (#1)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
* Server certificate: *.mail.com
* Server certificate: thawte SSL CA - G2
* Server certificate: thawte Primary Root CA
> HEAD / HTTP/1.1
> Host: www.mail.com
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Sun, 28 May 2017 22:02:16 GMT
Date: Sun, 28 May 2017 22:02:16 GMT
< Server: Apache
Server: Apache
< Vary: X-Forwarded-Proto,Host,Accept-Encoding
Vary: X-Forwarded-Proto,Host,Accept-Encoding
< Set-Cookie: cookieKID=kid%40autoref%40mail.com; Domain=.mail.com; Expires=Tue, 27-Jun-2017 22:02:16 GMT; Path=/
Set-Cookie: cookieKID=kid%40autoref%40mail.com; Domain=.mail.com; Expires=Tue, 27-Jun-2017 22:02:16 GMT; Path=/
< Set-Cookie: cookiePartner=kid%40autoref%40mail.com; Domain=.mail.com; Expires=Tue, 27-Jun-2017 22:02:16 GMT; Path=/
Set-Cookie: cookiePartner=kid%40autoref%40mail.com; Domain=.mail.com; Expires=Tue, 27-Jun-2017 22:02:16 GMT; Path=/
< Cache-Control: no-cache, no-store, must-revalidate
Cache-Control: no-cache, no-store, must-revalidate
< Pragma: no-cache
Pragma: no-cache
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Set-Cookie: JSESSIONID=F0BEF03C92839D69057FFB57C7FAA789; Path=/mailcom-webapp/; HttpOnly
Set-Cookie: JSESSIONID=F0BEF03C92839D69057FFB57C7FAA789; Path=/mailcom-webapp/; HttpOnly
< Content-Language: en-US
Content-Language: en-US
< Content-Length: 85237
Content-Length: 85237
< Connection: close
Connection: close
< Content-Type: text/html;charset=UTF-8
Content-Type: text/html;charset=UTF-8

< 
* Closing connection 1
curl -ILv http://www.mail.com 2>&1 | grep '^[<>\*].*$'