curl下载安装与使用

curl下载安装与使用

下载:

https://curl.haxx.se/download.html

安装:

二进制安装。即解压即可。

使用

1、获取页面内容。

不加任何参数时,默认会发送GET请求来获取url内容到标准输出。

curl url

D:\AppCache\GolangHome\src\learn>curl www.apple.com#===============================================================

D:\AppCache\GolangHome\src\learn>curl www.google.com

curl: (52) Empty reply from server

#===============================================================

D:\AppCache\GolangHome\src\learn>curl www.xiaomi.com

301 Moved Permanently

301 Moved Permanently


Powered by MiWeb

#==============================================================

D:\AppCache\GolangHome\src\learn>curl www.baidu.com

c.com/r/www/cache/bdorz/baidu.min.css>百度一下,你就知道

关于百度 About Baidu

©2017 Baidu 

href=http://www.baidu.com/duty/>使用百度前必读  意见反馈 京ICP证030173号 

#===================================================================D:\AppCache\GolangHome\src\learn>

分别测试了苹果、谷歌、小米、百度。发现获得的页面内容大小相差较大。苹果啥也不给,霸道。谷歌则给了一句温馨提示语。小米则简洁地回应了一个html,重定向了。百度则回应一堆信息。

2、获取http响应的头部信息。

D:\AppCache\GolangHome\src\learn>curl -I http://www.apple.com

HTTP/1.1 301 Moved Permanently

Server: GHost

Content-Length: 0

Location: https://www.apple.com/

Cache-Control: max-age=0

Expires: Sun, 22 Sep 2019 04:59:29 GMT

Date: Sun, 22 Sep 2019 04:59:29 GMT

Connection: keep-alive

strict-transport-security: max-age=31536000

Set-Cookie: geo=CN; path=/; domain=.apple.com

Set-Cookie: ccl=shCgHjtuYBarTIycW/rvIg==; path=/; domain=.apple.com

#===================================================================

D:\AppCache\GolangHome\src\learn>curl -I http://www.google.com

curl: (52) Empty reply from server

#====================================================================

D:\AppCache\GolangHome\src\learn>curl -I http://www.xiaomi.com

HTTP/1.1 301 Moved Permanently

Server: nginx

Date: Sun, 22 Sep 2019 04:59:53 GMT

Content-Type: text/html

Content-Length: 223

Connection: close

Location: https://www.mi.com

#===================================================================

D:\AppCache\GolangHome\src\learn>curl -I http://www.baidu.com

HTTP/1.1 200 OK

Server: bfe/1.0.8.18

Date: Sun, 22 Sep 2019 05:00:01 GMT

Content-Type: text/html

Content-Length: 277

Last-Modified: Mon, 13 Jun 2016 02:50:23 GMT

Connection: Keep-Alive

ETag: "575e1f6f-115"

Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform

Pragma: no-cache

Accept-Ranges: bytes

#==========================================================================

D:\AppCache\GolangHome\src\learn>

这次谷歌给的响应头依然是一句简短的提示语,太节约资源了。其他三个则普通给出响应头,其中苹果和小米都重定向了。

4、同时给出http的响应头和响应体。

D:\AppCache\GolangHome\src\learn>curl -i http://www.google.com

curl: (52) Empty reply from server

#===============================================================

D:\AppCache\GolangHome\src\learn>curl -i http://www.apple.com

HTTP/1.1 301 Moved Permanently

Server: GHost

Content-Length: 0

Location: https://www.apple.com/

Cache-Control: max-age=0

Expires: Sun, 22 Sep 2019 05:10:26 GMT

Date: Sun, 22 Sep 2019 05:10:26 GMT

Connection: keep-alive

strict-transport-security: max-age=31536000

Set-Cookie: geo=CN; path=/; domain=.apple.com

Set-Cookie: ccl=Pnj18CxjBB4h7LQaKIIkxg==; path=/; domain=.apple.com

#=====================================================================

D:\AppCache\GolangHome\src\learn>curl -i http://www.xiaomi.com

HTTP/1.1 301 Moved Permanently

Server: nginx

Date: Sun, 22 Sep 2019 05:10:35 GMT

Content-Type: text/html

Content-Length: 223

Connection: close

Location: https://www.mi.com

301 Moved Permanently

301 Moved Permanently


Powered by MiWeb

#=============================================================

D:\AppCache\GolangHome\src\learn>curl -i http://www.baidu.com

HTTP/1.1 200 OK

Server: bfe/1.0.8.18

Date: Sun, 22 Sep 2019 05:10:47 GMT

Content-Type: text/html

Content-Length: 2381

Last-Modified: Mon, 23 Jan 2017 13:28:12 GMT

Connection: Keep-Alive

ETag: "588604ec-94d"

Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform

Pragma: no-cache

Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/

Accept-Ranges: bytes

c.com/r/www/cache/bdorz/baidu.min.css>百度一下,你就知道

关于百度 About Baidu

©2017 Baidu 

href=http://www.baidu.com/duty/>使用百度前必读  意见反馈 京ICP证030173号 

#====================================================

D:\AppCache\GolangHome\src\learn>

谷歌依旧发挥着极简风格,就一句话。苹果给头不给体。小米则都给。百度则臃肿不堪。

更多创意作品