zoukankan      html  css  js  c++  java
  • curl命令解析

    curl命令可以实现http post或者get的请求,是linux下的命令行工具

    1.1.直接请求url,打印标准输出

    1.2.使用-o参数,可以标准输出到指定的位置

    [root@VM-3-10-13 ~]# curl https://www.baidu.com -o /tmp/baidu.tmp
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  2443  100  2443    0     0  12587      0 --:--:-- --:--:-- --:--:-- 12658
    

    可以看到整个下载的数据大小和时间

    1.3. --head显示url的header信息

    [root@VM-3-10-13 ~]# curl  --head https://www.baidu.com
    HTTP/1.1 200 OK
    Server: bfe/1.0.8.18
    Date: Tue, 21 Mar 2017 02:17:37 GMT
    Content-Type: text/html
    Content-Length: 277
    Connection: keep-alive
    Last-Modified: Mon, 13 Jun 2016 02:50:01 GMT
    ETag: "575e1f59-115"
    Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
    Pragma: no-cache
    Accept-Ranges: bytes
    

    1.4. -x 使用http代理访问

    1.5.cookie

    curl -c /tmp/cookies https://www.baidu.com   #接收保存cookie
    
    curl -b /tmp/cookies http://www.baidu.com    #发送cookie
    curl -b "k1=v1;k2=v2" http://www.baidu.com   #发送cookie
    

    1.6.发送数据

    以get方式提交:

     curl -G  -d "username=qiangqiang.chang&password=xxxxxx" http://jumpserver.i.beebank.com/login/
    

    以post方式提交:

    curl  -d "username=qiangqiang.chang&password=xxxxxx" http://jumpserver.i.beebank.com/login/
    

    1.7.http header处理

    设置http请求头信息

    curl -A 'Mozilla/5.0' http://www.baidu.com    #设置User-Agent
    curl  -e " http://jumpserver.i.beebank.com/login/" http://jumpserver.i.beebank.com    #设置Referer
    curl -H "Connection:keep-alive 
     User-Agent: Mozilla/5.0" http://www.aiezu.com    #设置自定义的头信息
    

    http header处理:

    [root@linux-node1 ~]# curl -I http://www.baidu.com   #获取header信息
    HTTP/1.1 200 OK
    Server: bfe/1.0.8.18
    Date: Tue, 21 Mar 2017 03:22:52 GMT
    Content-Type: text/html
    Content-Length: 277
    Last-Modified: Mon, 13 Jun 2016 02:50:04 GMT
    Connection: Keep-Alive
    ETag: "575e1f5c-115"
    Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
    Pragma: no-cache
    Accept-Ranges: bytes
    
    curl -D  /tmp/header1.tmp -s http://www.baidu.com  #将相应头信息保存到指定的文件中
    

    1.8.登录认证

    curl -u qianngqiang.chang:xxxxx http://jumpserver.i.beebank.com/   
    

      

  • 相关阅读:
    Eclipse
    svn 常用
    spidermonkey编译
    float format 显示
    点击6次修改服务器地址
    UITextField字数限制
    UINavigationController
    运行时runtime
    IOS 技术与面试
    Cocos2dx笔记
  • 原文地址:https://www.cnblogs.com/cqq-20151202/p/6593471.html
Copyright © 2011-2022 走看看