curl 访问,查看返回状态码
#!/bin/bash
CURL=(www.baidu.com)
for i in ${CURL[@]}
do
http_code=$(curl -I -s $i -w %{http_code}); echo $i status: ${http_code:9:3}
done
#-----------------------------------------------
root@dell:~# bash curl_test.sh
www.baidu.com status: 200
第二种非for循环
http_code=$(curl -I -s www.baidu.com -w %{http_code}); echo www.bai.com status: ${http_code:9:3}
www.baidu.com status: 200
注:curl访问带有参数的链接时,(确保你参数正确)可能会出现以下情况
#这里有两个参数,但是这样访问的话,第二个参数的值 ,也就是 b 的值会取不到 导致访问失败
root@dell:~# curl -I http://www.test.com?a=v1&b=v2
#需要在curl 后的链接加上 “ ”,即可访问成功
root@dell:~# curl -I “ http://www.test.com?a=v1&b=v2 ”
浙公网安备 33010602011771号