Site icon moneyslow.com

Curl 命令用法

获取页面内容

当我们不加任何选项使用 curl 时,默认会发送 GET 请求来获取链接内容到标准输出。

curl http://www.moneyslow.com


显示 HTTP 头

如果我们只想要显示 HTTP 头,而不显示文件内容,可以使用 -I 选项:

curl -I http://www.moneyslow.com

输出为:

HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Thu, 11 May 2017 08:24:45 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 24206
Connection: keep-alive
X-Powered-By: Express
Cache-Control: public, max-age=0
ETag: W/"5e8e-Yw5ZdnVVly9/aEnMX7fVXQ"
Vary: Accept-Encoding

也可以同时显示 HTTP 头和文件内容,使用 -i 选项:

curl -i http://www.moneyslow.com

输出为:

HTTP/1.1 200 OK

Server: nginx/1.10.3

Date: Thu, 11 May 2017 08:25:46 GMT

Content-Type: text/html; charset=utf-8   Content-Length: 24206

Connection: keep-alive

X-Powered-By: Express

Cache-Control: public, max-age=0

ETag: W/"5e8e-Yw5ZdnVVly9/aEnMX7fVXQ"

Vary: Accept-Encoding

<!DOCTYPE html>

<html>

......

</html>


将链接保存到文件

我们可以使用 > 符号将输出重定向到本地文件中。

curl http://www.moneyslow.com > index.html

也可以通过 curl 自带的 -o/-O 选项将内容保存到文件中。

Exit mobile version