curl获取http返回的状态码
curl -i -s -m 10 http://192.158.1.11:8080/test/ |grep HTTP|awk '{print $2}'-i 仅测试HTTP请求头-s不输出任何东西-m 设置请求超时时间,单位/秒以下是脚本分步执行结果[root@2 test]# curl-i -s http://192.158.1.11:8080/test/##调用页面HTTP/1.1 200Set
·
方式一
curl -I -s -m 10 http://192.158.1.11:8080/test/ |grep HTTP|awk '{print $2}'
方式二
curl -I -o /dev/null -s -w %{http_code} http://192.168.195.129:8080
-I 仅输出HTTP请求头
-s 不输出任何东西
-m 设置请求超时时间,单位/秒
以下是脚本分步执行结果
[root@2 test]# curl -i -s http://192.158.1.11:8080/test/ ##调用页面
HTTP/1.1 200
Set-Cookie: JSESSIONID=00553C870452B5D8527ACCAB3DAF55FA; Path=/QZ-BKSQ; HttpOnly
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Last-Modified: Sat, 23 Oct 2021 07:03:37 GMT
Accept-Ranges: bytes
Content-Type: text/html;charset=ISO-8859-1
Content-Language: en-US
Content-Length: 194
Date: Tue, 30 Nov 2021 04:14:26 GMT
<!DOCTYPE HTML>
<html>
<head>
<title>succeed</title>
<meta charset="UTF-8">
</head>
<body>
<h1><i style="color:#18ec18">SUCCEED~,</i><i> BKSQ</i>部署成功!</h1>
</body>
</html>
[root@2 test]# curl -i -s http://192.158.1.11:8080/test/ |grep HTTP ##调用页面,查找http请求头所在行
HTTP/1.1 200
[root@2 test]# curl -i -s http://192.158.1.11:8080/test/ |grep HTTP|awk '{print $2}' ##在请求头中截取状态码
200
[root@2 test]#
更多推荐
已为社区贡献9条内容
所有评论(0)