curl命令

连接https网站,加上-I选项,只打印响应Header,不打印响应body

# curl -I https://www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 277
Content-Type: text/html
Date: Fri, 29 Mar 2019 02:43:25 GMT
Etag: "575e1f5c-115"
Last-Modified: Mon, 13 Jun 2016 02:50:04 GMT
Pragma: no-cache
Server: bfe/1.0.8.18

连接测试用的https网站,因为使用了自己签发的证书而报错

# curl -I https://www.test.com
curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

加上-k选项,关闭对测试用https网站证书的验证

# curl -I -k https://www.test.com
HTTP/1.1 200 OK
Date: Fri, 29 Mar 2019 02:44:50 GMT
Server: httpserver
X-Frame-Options: sameorigin
X-XSS-Protection: 1, mode=block
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=30, includeSubDomains
Expect-CT: enforce, max-age=86400
Last-Modified: Mon, 25 Mar 2019 06:12:51 GMT
ETag: "18-584e5182d0cc3"
Accept-Ranges: bytes
Content-Length: 24
Content-Type: text/html

去掉-I选项,不打印响应Header,打印响应body

# curl -k https://www.test.com
index html 192.168.1.82

加上-i选项,打印响应Header和body

# curl -k -i https://www.test.com
HTTP/1.1 200 OK
Date: Fri, 29 Mar 2019 02:54:29 GMT
Server: httpserver
X-Frame-Options: sameorigin
X-XSS-Protection: 1, mode=block
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=30, includeSubDomains
Expect-CT: enforce, max-age=86400
Last-Modified: Mon, 25 Mar 2019 06:19:58 GMT
ETag: "18-584e531a39358"
Accept-Ranges: bytes
Content-Length: 24
Content-Type: text/html

index html 192.168.1.83

加上–interface选项,指定本地IP地址

# curl --interface ens33:0 -k https://www.test.com 
index html 192.168.1.83

加上-w选项,打印使用的本地IP地址及端口

# curl --interface ens33:0 -k https://www.test.com -w "%{local_ip}:%{local_port}\n"                    
index html 192.168.1.82
192.168.1.71:56802

加上–local-port选项,指定本地端口

# curl --interface ens33:0 --local-port 9999 -k https://www.test.com -w "%{local_ip}:%{local_port}\n" 
index html 192.168.1.82
192.168.1.71:9999

使用–local-port选项,指定本地端口范围

# curl --interface ens33:0 --local-port 22-999 -k https://www.test.com -w "%{local_ip}:%{local_port}\n"     
index html 192.168.1.83
192.168.1.71:23

使用-g选项关闭通配符开关,以便访问IPv6网站

# curl -k -g https://[2001:123::81] -w "%{local_ip}:%{local_port}\n"
index html 192.168.1.83
2001:123::2:82:47258

使用-b选项,携带cookie参数

# curl -Ik -b "ROUTEID=.1" https://www.test.com/test_bytraffic.html
HTTP/1.1 200 OK
Date: Fri, 29 Mar 2019 03:06:42 GMT
Server: httpserver
X-Frame-Options: sameorigin
X-XSS-Protection: 1, mode=block
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=30, includeSubDomains
Expect-CT: enforce, max-age=86400
Last-Modified: Thu, 28 Mar 2019 03:32:48 GMT
ETag: "98972f-5851f35578f66"
Accept-Ranges: bytes
Content-Length: 10000175
Content-Type: text/html

测试负载均衡效果,响应Header中的Content-Length字段有不同

# curl -Ik -b "ROUTEID=.2" https://www.test.com/test_bytraffic.html 
HTTP/1.1 200 OK
Date: Fri, 29 Mar 2019 03:06:46 GMT
Server: httpserver
X-Frame-Options: sameorigin
X-XSS-Protection: 1, mode=block
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=30, includeSubDomains
Expect-CT: enforce, max-age=86400
Last-Modified: Thu, 28 Mar 2019 02:17:12 GMT
ETag: "18-5851e26f62e27"
Accept-Ranges: bytes
Content-Length: 24
Content-Type: text/html

添加–http2选项,支持HTTP/2

# curl --http2 -I https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/css/super_min_353cb37f.css
HTTP/2 200 
server: JSP3/2.0.14
date: Fri, 29 Mar 2019 06:53:49 GMT
content-type: text/css
content-length: 25542
etag: "5c7e1b2f-63c6"
last-modified: Tue, 05 Mar 2019 06:46:07 GMT
expires: Thu, 04 Apr 2019 10:51:09 GMT
age: 2059360
accept-ranges: bytes
cache-control: max-age=2592000
vary: Accept-Encoding
ohc-response-time: 1 0 0 0 0 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值