zoukankan      html  css  js  c++  java
  • 002_curl及postman专题

     一、

    步骤 1: 下载cURL工具

    使用您的Windows机器从cURL web站点下载最新版本的cURL:

    (1) 通常情况下,多数的Windows用户可以从官网下载页面http://curl.haxx.se/download.html中下载最新版本,如下所示:

    Win32 2000/XP zip | 7.39.0 | binary | SSL | Günter Knauf | 2.06 MB,因为版本更新,版本号可能有变化。

    (2) 其它操作系统,可以从cURL web站点页面的"Select Operating System"标题下的“Show package for:”的列表框选择适合的版本后下载。

    请解压cURL的压缩文件到一个很容易访问的目录(例如c:curl)。

    步骤 2: curl管道操作

    使用一个简单的命令上传日志:打开一个终端窗口,输入您的用户标识符,然后运行它,把样本数据上传到您的帐户。

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

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

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

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

    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

    二、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

     三、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}	
    %{http_code}	
    %{http_connect}	
    #curl输出结果如下:
    http://127.0.0.1:8083	200	000  

    参数详解:

    %{url_effective}	          这个url是最后获取的,如果在curl后添加"headers"请求参数这个是非常有用的,eg:
    %{http_code}	              HTTP(S)或FTP(s)请求响应状态码,在7.18.2版本中等同于"response_code",eg:200      **重要**
    %{http_connect}	           在最后的响应,即(从proxy代理服务器到curl连接请求之前)的请求number,这个变量添加在7.12.4版本中,eg:000
    %{time_total}	             总的请求时间,以秒为单位展示,精度到毫秒,从curl开始到最终的返回的全部的请求耗时,eg:0.015      **重要**
    %{time_namelookup}	        从curl开始到域名解析完成所花费的时间,以秒为单位展示,eg:0.000                    **重要**
    %{time_connect}	           从curl开始到TCP连接远程主机(或proxy)完成所花费的时间,以秒为单位展示,eg:0.000      
    %{time_appconnect}	        从curl开始到SSL/SSH等连接或握手到远程主机完成所花费的时间,以秒为单位展示,eg:0.000
    %{time_pretransfer}	       从curl开始到文件传输开始,包括预先开始传输期间的命令和涉及到特殊协议的协商所花费的时间,以秒为单位展示,eg:0.000
    %{time_redirect}	          它包括所有的如域名解析/连接/预先传输/最终的传输开始,该变量展示了对于多次重定向所耗费的完整执行时间,以秒为单位展示,eg:0.000  **重要**
    %{time_starttransfer}	     它包括从curl开始到第一字节开始传输,包括%{time_pretransfer}和服务器计算结果的时间,以秒为单位展示,eg:1.880
    %{size_download}	          curl请求下载总的字节数,eg:7626    **重要**
    %{size_upload}	            curl请求上传总的字节数,eg:0
    %{size_header}	            curl请求下载headers的总的字节数,eg:208   **重要**
    %{size_request}	           curl在http请求中发送的总的字节数,eg:167  **重要**
    %{speed_download}	         curl请求评估整个完成下载的平均下载速度,eg:517122.000     **重要**
    %{speed_upload}	           curl请求评估整个完成上传的平均速度,eg:0.000
    %{content_type}	           curl请求的Content-Type文档请求类型,eg:text/html;charset=UTF-8   **重要**
    %{num_connects}	           在最近的传输中建立新的连接的数量,eg:1  **重要** 
    %{num_redirects}	          在curl请求中重定向的数量,eg:0     **重要**        
    %{redirect_url}	           当一个HTTP请求没有用-L选项(跟踪URL重定向),这个变量将展示实际的你想请求的实际URL的重定向,在7.18.2版本中添加的功能
    %{ftp_entry_path}	         当登录到远程FTP server时,curl结束的初始路径
    %{ssl_verify_result}	      结果展示对端server对ssl确认请求情况,0意味着确认是成功的,eg:0
    

    四、使用curl命令指定ip访问url

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

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

    五、提交数据

    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

    六、

    --cookie和--header添加cookie和header头

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

     七、使用curl做域名临时绑定的不用写host的测试

    curl https://www.uuwatch.me --resolve www.uuwatch.me:443:10.108.8.142 -v
    

    八、注意用postman模拟请求的时候请求头的设置

    是用postman模拟

     
  • 相关阅读:
    Java基本语法(一)
    JAVA菜鸟入门HelloWorld
    python 练习题-质数
    python 字符串转运算符
    python 提取不重复的整数
    python 句子逆序
    python 数字颠倒
    python 字符个数统计
    python 练习题-计算字符个数
    python int型正整数在内存中存储为1的个数
  • 原文地址:https://www.cnblogs.com/itcomputer/p/6240734.html
Copyright © 2011-2022 走看看