curl\curl_使用cURL检索标题

curl\curl

We all know the cURL is incredibly useful.  We can retrieve remote content with curl, post to a remote URL, and perform hundreds of other tasks.  One simple task that can be completed is simply retrieving basic response headers.  To test the robot indexing prevention header I added to the Mozilla Developer Network, I used one simple cURL command to grab all headers from an address.

我们都知道cURL非常有用。 我们可以使用curl检索远程内容发布到远程URL并执行其他数百项任务。 可以完成的一个简单任务就是简单地检索基本响应头。 为了测试我添加到Mozilla开发人员网络的 防止机器人索引编制标头 ,我使用了一个简单的cURL命令从地址中获取所有标头。

贝壳 (The Shell)

The cURL command is short and sweet:

cURL命令简短而有趣:


curl -I davidwalsh.name


Said command provides a list that looks similar to:

所述命令提供了类似于以下内容的列表:


HTTP/1.1 200 OK
Date: Fri, 14 Sep 2012 21:51:17 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Fri, 14 Sep 2012 21:51:00 GMT
Accept-Ranges: bytes
Content-Length: 10910
Cache-Control: max-age=1, private, must-revalidate
Expires: Fri, 14 Sep 2012 22:51:00 GMT
Vary: Accept-Encoding,Cookie
X-Powered-By: W3 Total Cache/0.9.2.4
X-Pingback: https://davidwalsh.name/xmlrpc.php
Pragma: public
Connection: close
Content-Type: text/html; charset=UTF-8


This command is helpful when ensuring a given header has been correctly set within your programming, as well as seeing where a given short URL may redirect to:

在确保已在编程中正确设置了给定的标头以及查看给定的短URL可能重定向到的位置时,此命令很有用。


$ curl -I bit.ly/Q8f9o

HTTP/1.1 301 Moved
Server: nginx
Date: Fri, 14 Sep 2012 21:53:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: _bit=5053a74a-0011d-0688d-311cf10a;domain=.bit.ly;expires=Wed Mar 13 21:53:14 2013;path=/; HttpOnly
Cache-control: private; max-age=90
Location: https://davidwalsh.name/
MIME-Version: 1.0
Content-Length: 115


It's also useful to see the server name, expires information and more.  I also appreciate that it's a clean list and no other information is pushed into the response.  If you get some time, cURL out to different popular domains and see what headers they send -- you could be surprised!

查看服务器名称,过期信息等也很有用。 我也很欣赏这是一个干净的清单,并且没有其他信息被发送到响应中。 如果有时间,请cURL到不同的流行域,并查看它们发送了哪些标头-您可能会感到惊讶!

翻译自: https://davidwalsh.name/curl-headers

curl\curl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值