002_curl及postman專題 使用curl命令指定ip訪問url

 1、

步驟 1: 下載cURL工具

使用您的Windows機器從cURL web站點下載最新版本的cURL:html

(1) 一般狀況下,多數的Windows用戶能夠從官網下載頁面http://curl.haxx.se/download.html中下載最新版本,以下所示:python

Win32 2000/XP zip | 7.39.0 | binary | SSL | Günter Knauf | 2.06 MB,由於版本更新,版本號可能有變化。linux

(2) 其它操做系統,能夠從cURL web站點頁面的"Select Operating System"標題下的「Show package for:」的列表框選擇適合的版本後下載。web

請解壓cURL的壓縮文件到一個很容易訪問的目錄(例如c:\curl)。json

步驟 2: curl管道操做

使用一個簡單的命令上傳日誌:打開一個終端窗口,輸入您的用戶標識符,而後運行它,把樣本數據上傳到您的賬戶。api

 -X/--request <command> Specify request command to usebash

 -k/--insecure      Allow connections to SSL sites without certs (H)服務器

 -H/--header <line> Custom header to pass to server (H)  cookie

 @- 管道操做
 --data-binary <data> HTTP POST binary data (H)
app

1 curl -k -L https://www.rizhiyi.com/install/RizhiyiSample.log | curl -k -X POST -H "content-type:text/plain" --data-binary @- http://192.168.1.38:5180/bulk/06f69fae723038bbc5d75d29564051ea/tag/test

2、curl經常使用參數詳解

<1>-T/--upload-file <file> Transfer <file> to remote site

上傳日誌例子==> 粘貼如下命令到終端窗口,而後將本地日誌上傳到您的賬戶。

curl -X POST -T FILE.TXT http://192.168.1.38:5180/bulk/06f69fae723038bbc5d75d29564051ea/tag/test

<2> -O/--remote-name   Write output to a file named as the remote file

curl -O https://www.rizhiyi.com/install/configure_linux_rsyslog.sh -k

 3、eleman監測

cat validate.sh

$ cat validate.sh
#!/usr/bin/env bash
while [ true ]
do
    sleep 1
    HTTP_CODE=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://localhost:8081/api/login_status`
    echo "http code: ${HTTP_CODE}"
    if [ ${HTTP_CODE} -eq 200 ] || [ ${HTTP_CODE} -eq 405 ]
    then
        exit 0
    fi
done

curl獲取響應時間拓展:"-w"參數

-o/--output <file>    #把curl請求內容輸出到文件

-s/--silent    #不要輸出請求進程信息和錯誤信息

-w/--write-out <format>

#你能夠把變量寫成文件的方式,而後加載
curl -o /dev/null -s -w "@readload" 127.0.0.1:8083
cat  readload
%{url_effective}\t
%{http_code}\t
%{http_connect}\t
#curl輸出結果以下:
http://127.0.0.1:8083	200	000  

參數詳解:

%{url_effective}\t          這個url是最後獲取的,若是在curl後添加"headers"請求參數這個是很是有用的,eg:
%{http_code}\t              HTTP(S)或FTP(s)請求響應狀態碼,在7.18.2版本中等同於"response_code",eg:200      **重要**
%{http_connect}\t           在最後的響應,即(從proxy代理服務器到curl鏈接請求以前)的請求number,這個變量添加在7.12.4版本中,eg:000
%{time_total}\t             總的請求時間,以秒爲單位展現,精度到毫秒,從curl開始到最終的返回的所有的請求耗時,eg:0.015      **重要**
%{time_namelookup}\t        從curl開始到域名解析完成所花費的時間,以秒爲單位展現,eg:0.000                    **重要**
%{time_connect}\t           從curl開始到TCP鏈接遠程主機(或proxy)完成所花費的時間,以秒爲單位展現,eg:0.000      
%{time_appconnect}\t        從curl開始到SSL/SSH等鏈接或握手到遠程主機完成所花費的時間,以秒爲單位展現,eg:0.000
%{time_pretransfer}\t       從curl開始到文件傳輸開始,包括預先開始傳輸期間的命令和涉及到特殊協議的協商所花費的時間,以秒爲單位展現,eg:0.000
%{time_redirect}\t          它包括全部的如域名解析/鏈接/預先傳輸/最終的傳輸開始,該變量展現了對於屢次重定向所耗費的完整執行時間,以秒爲單位展現,eg:0.000  **重要**
%{time_starttransfer}\t     它包括從curl開始到第一字節開始傳輸,包括%{time_pretransfer}和服務器計算結果的時間,以秒爲單位展現,eg:1.880
%{size_download}\t          curl請求下載總的字節數,eg:7626    **重要**
%{size_upload}\t            curl請求上傳總的字節數,eg:0
%{size_header}\t            curl請求下載headers的總的字節數,eg:208   **重要**
%{size_request}\t           curl在http請求中發送的總的字節數,eg:167  **重要**
%{speed_download}\t         curl請求評估整個完成下載的平均下載速度,eg:517122.000     **重要**
%{speed_upload}\t           curl請求評估整個完成上傳的平均速度,eg:0.000
%{content_type}\t           curl請求的Content-Type文檔請求類型,eg:text/html;charset=UTF-8   **重要**
%{num_connects}\t           在最近的傳輸中創建新的鏈接的數量,eg:1  **重要** 
%{num_redirects}\t          在curl請求中重定向的數量,eg:0     **重要**        
%{redirect_url}\t           當一個HTTP請求沒有用-L選項(跟蹤URL重定向),這個變量將展現實際的你想請求的實際URL的重定向,在7.18.2版本中添加的功能
%{ftp_entry_path}\t         當登陸到遠程FTP server時,curl結束的初始路徑
%{ssl_verify_result}\t      結果展現對端server對ssl確認請求狀況,0意味着確認是成功的,eg:0

4、使用curl命令指定ip訪問url

curl -H ‘Host:baidu.com’ http://10.12.20.21

 參考:http://blog.51yip.com/linux/1049.html

5、提交數據

curl -l -H "Content-type: application/json" -X POST -d '{"test1":"1.0","test2":{"req":"123"},"iface":"test.test.Service","method":"testTask","args":{}}' http://www.example:6666/rpc

6、

--cookie和--header添加cookie和header頭

參考連接:http://joelpm.com/curl/tools/2010/06/17/curl-with-cookies-and-headers.html 

 7、使用curl作域名臨時綁定的不用寫host的測試

curl https://www.uuwatch.me --resolve www.uuwatch.me:443:10.108.8.142 -v
相關文章
相關標籤/搜索