curl官網:
ref:https://curl.haxx.se/docs/manpage.html
常用的字符界面web 客戶端
elinks --dump
curl -so /dev/null -w "%{time_total},%{time_namelookup},%{time_connect},%{time_pretransfer},%{time_redirect},%{time_starttransfer}\n" http://172.16.5.80:9081/ROOT/login.jsp
wget --http-user=admin --http-passwd=admin http://172.16.5.137:8161/admin/queues.jsp
curl獲取狀態碼
curl -I -m 10 -o /dev/null -s -w %{http_code} news.ehomepay.com.cn
-I獲取頭文件
curl --connect-timeout 20 -m 20 -o /dev/null -s -w %{http_code} http://172.26.113.194/
--connect-timeout 20 最大連接時間 20s ,如果連接上後,時間不在計算
-m 20 最大執行時間 20秒 ,總共的連接時不能超過20秒
-o /dev/null 輸出信息不顯示
-s 安靜輸出模式
-w %{http_code} 只輸出狀態碼
curl下載
curl --silent http://172.16.4.250/tools/ae_scan_linux.sh -o scan.sh
curl指定用戶密碼
curl -u username:pass http://www.xxx.com
curl -u read:passwd ftp://10.12.1.101
#curl通過 "@"參數進行上傳文件 curl上傳文件
curl --header "Content-Type: text/xml" --data-binary @$OUTPUTFILE "$protocol://$hostName:$portNo/discoveryServlet/WsDiscoveryServlet?COMPUTERNAME=$COMPUTERNAME"
#wget 通過--post-file進行上傳文件
wget "$protocol://$hostName:$portNo/discoveryServlet/WsDiscoveryServlet?COMPUTERNAME=$COMPUTERNAME" --post-file=./$COMPUTERNAME.xml --header="Content-Type:text/xml" > /dev/null 2>&1
culr post 請求
注意& 是分隔符
特殊字符 需要轉義 \
-d 接 post 參數
#curl http://172.16.4.134/sql_insert.php -d "user=user01&password=123123&ip=172.16.15.17&datetime=2014-09-30 16:53:00&system_load=22.31"
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<body>
172.16.15.17 2014-09-30 16:53:00 22.31 xixi</body>
</head>
</html>
culr post 請求
curl -d 'userName=13141026305&userPwd=1U8JkB4USEpzmTjbZfq\/CQ\=\=&ck=744336c7F0c8a4c0D386246990c37b51' http://10.35.13.103:8080/ROOT/login
curl重啓comm 定期重啓comm
curl -d "patch_number=common&system=new_online_restart" ttp://172.16.4.134/update_ol/do_ol_publish.php
curl_QA
##################################################
curl訪問web服務狀態碼爲000
1.如果是有時候返回200,有時候返回000,原因可能是超時時間設置的太短了,導致超時,所以返回狀態碼爲000
解決方式:
就是延長超時時間-m 50 。
curl -k -I -m 50 -o /dev/null -s -w "%{http_code} %{time_total}" https://www.ehomepay.com.cn
2.curl訪問不信任的https
curl通過https訪問內網服務器的時候,會出現不信任證書的情況,導致直接返回狀態碼爲000,解決方式添加:
-k/--insecure
(SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers. All
SSL connections are attempted to be made secure by using the CA certificate bundle installed by
default. This makes all connections considered "insecure" to fail unless -k/--insecure is used.
If this option is used twice, the second time will again disable it.
curl -k -I -m 50 -o /dev/null -s -w "%{http_code} %{time_total}" https://10.12.8.21
##################################################
wget 下載https文件的時候需要添加 --no-check-certificate
但是此處下載還是報錯。
[root@RNp-Git01 ~]# wget --no-check-certificate https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz
--2015-11-13 13:03:23-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz
Resolving fastdl.mongodb.org... 54.230.124.82, 54.230.124.117, 54.230.124.81, ...
Connecting to fastdl.mongodb.org|54.230.124.82|:443... connected.
OpenSSL: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
Unable to establish SSL connection.
解決方式
通過curl下載https,curl下載的時候提示不支持https,可以添加如下參數 https下載
curl -O -L https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz
##################################################
此處是網上發現的,感覺很不錯,特此推薦
#########################################################
設置curl的輸出格式,輸出標準化的日誌格式
# cat curl-format.txt
\n
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
\n
# curl -w "@curl-format.txt" -o /dev/null -s https://www.ehomepay.com.cn
time_namelookup: 0.003
time_connect: 0.005
time_appconnect: 0.128
time_pretransfer: 0.128
time_redirect: 0.000
time_starttransfer: 1.950
----------
time_total: 1.960
ref:https://curl.haxx.se/docs/manpage.html
常用的字符界面web 客戶端
elinks --dump
curl -so /dev/null -w "%{time_total},%{time_namelookup},%{time_connect},%{time_pretransfer},%{time_redirect},%{time_starttransfer}\n" http://172.16.5.80:9081/ROOT/login.jsp
wget --http-user=admin --http-passwd=admin http://172.16.5.137:8161/admin/queues.jsp
curl獲取狀態碼
curl -I -m 10 -o /dev/null -s -w %{http_code} news.ehomepay.com.cn
-I獲取頭文件
curl --connect-timeout 20 -m 20 -o /dev/null -s -w %{http_code} http://172.26.113.194/
--connect-timeout 20 最大連接時間 20s ,如果連接上後,時間不在計算
-m 20 最大執行時間 20秒 ,總共的連接時不能超過20秒
-o /dev/null 輸出信息不顯示
-s 安靜輸出模式
-w %{http_code} 只輸出狀態碼
curl下載
curl --silent http://172.16.4.250/tools/ae_scan_linux.sh -o scan.sh
curl指定用戶密碼
curl -u username:pass http://www.xxx.com
curl -u read:passwd ftp://10.12.1.101
#curl通過 "@"參數進行上傳文件 curl上傳文件
curl --header "Content-Type: text/xml" --data-binary @$OUTPUTFILE "$protocol://$hostName:$portNo/discoveryServlet/WsDiscoveryServlet?COMPUTERNAME=$COMPUTERNAME"
#wget 通過--post-file進行上傳文件
wget "$protocol://$hostName:$portNo/discoveryServlet/WsDiscoveryServlet?COMPUTERNAME=$COMPUTERNAME" --post-file=./$COMPUTERNAME.xml --header="Content-Type:text/xml" > /dev/null 2>&1
culr post 請求
注意& 是分隔符
特殊字符 需要轉義 \
-d 接 post 參數
#curl http://172.16.4.134/sql_insert.php -d "user=user01&password=123123&ip=172.16.15.17&datetime=2014-09-30 16:53:00&system_load=22.31"
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<body>
172.16.15.17 2014-09-30 16:53:00 22.31 xixi</body>
</head>
</html>
culr post 請求
curl -d 'userName=13141026305&userPwd=1U8JkB4USEpzmTjbZfq\/CQ\=\=&ck=744336c7F0c8a4c0D386246990c37b51' http://10.35.13.103:8080/ROOT/login
curl重啓comm 定期重啓comm
curl -d "patch_number=common&system=new_online_restart" ttp://172.16.4.134/update_ol/do_ol_publish.php
curl_QA
##################################################
curl訪問web服務狀態碼爲000
1.如果是有時候返回200,有時候返回000,原因可能是超時時間設置的太短了,導致超時,所以返回狀態碼爲000
解決方式:
就是延長超時時間-m 50 。
curl -k -I -m 50 -o /dev/null -s -w "%{http_code} %{time_total}" https://www.ehomepay.com.cn
2.curl訪問不信任的https
curl通過https訪問內網服務器的時候,會出現不信任證書的情況,導致直接返回狀態碼爲000,解決方式添加:
-k/--insecure
(SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers. All
SSL connections are attempted to be made secure by using the CA certificate bundle installed by
default. This makes all connections considered "insecure" to fail unless -k/--insecure is used.
If this option is used twice, the second time will again disable it.
curl -k -I -m 50 -o /dev/null -s -w "%{http_code} %{time_total}" https://10.12.8.21
##################################################
wget 下載https文件的時候需要添加 --no-check-certificate
但是此處下載還是報錯。
[root@RNp-Git01 ~]# wget --no-check-certificate https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz
--2015-11-13 13:03:23-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz
Resolving fastdl.mongodb.org... 54.230.124.82, 54.230.124.117, 54.230.124.81, ...
Connecting to fastdl.mongodb.org|54.230.124.82|:443... connected.
OpenSSL: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
Unable to establish SSL connection.
解決方式
通過curl下載https,curl下載的時候提示不支持https,可以添加如下參數 https下載
curl -O -L https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz
##################################################
此處是網上發現的,感覺很不錯,特此推薦
#########################################################
設置curl的輸出格式,輸出標準化的日誌格式
# cat curl-format.txt
\n
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
\n
# curl -w "@curl-format.txt" -o /dev/null -s https://www.ehomepay.com.cn
time_namelookup: 0.003
time_connect: 0.005
time_appconnect: 0.128
time_pretransfer: 0.128
time_redirect: 0.000
time_starttransfer: 1.950
----------
time_total: 1.960