• linux-curl工具使用


    环境:centos

    1、超时参数解析

    #使用curl时,有两个超时时间:
    #--connect-timeout <seconds>     是连接超时时间
    #-m/--max-time     <seconds>     是整个过程允许的最大时间 
    #下面表示连接百度20秒没有连接到百度退出,整个过程40s没有返回退出
    curl --connect-timeout 20 -m 40 https://www.baidu.com
    

    2、静默不输出信息 -s 参数

    [root@minion246 wj]# curl http://gayd.sczwfw.gov.cn:8903|grep mess                     #不带-s
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100    62  100    62    0     0   1444      0 --:--:-- --:--:-- --:--:--  1476
    {"code":40966,"message":"请求的应用token位数不正确"}
    [root@minion246 wj]# curl -s http://gayd.sczwfw.gov.cn:8903|grep mess                 #带参数-s
    {"code":40966,"message":"请求的应用token位数不正确"}
    

    3、获取对方的响应首部信息 -I

    [root@minion246 wj]# curl -I http://gayd.sczwfw.gov.cn
    HTTP/1.1 200 OK
    Vary: Accept-Encoding
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET,HEAD,PUT,POST,DELETE
    Content-Type: text/plain; charset=utf-8
    Content-Length: 0
    Date: Wed, 23 Sep 2020 03:16:25 GMT
    Connection: keep-alive
    

    4、显示网页的全部信息

    curl -i  "https://www.baidu.com" 
    

    5、显示一次的http请求的通信过程

    [root@minion246 wj]# curl -v http://gayd.sczwfw.gov.cn
    * About to connect() to gayd.sczwfw.gov.cn port 80 (#0)
    *   Trying 202.61.88.250...
    * Connected to gayd.sczwfw.gov.cn (202.61.88.250) port 80 (#0)
    > GET / HTTP/1.1
    > User-Agent: curl/7.29.0
    > Host: gayd.sczwfw.gov.cn
    > Accept: */*
    

    6、模拟get 请求

    当发起http请求时,curl会默认发起GET请求,也可以"-X GET"方式指定
    curl -X GET http://www.baidu.com
    

    7、模拟post提交

    1、有body参数
    curl -d "param1=value1&param2=value2" "http://www.baidu.com"
    2、有JOSN格式的body和header入参
    curl -s -l -H "Content-type: application/json" -X POST -d @/wj/smrz.xml https://gayd.sczwfw.gov.cn/e62894182afb55c9a65baab9ba9b6d18
    

      

    做一个决定,并不难,难的是付诸行动,并且坚持到底。
  • 相关阅读:
    多表链接 Left join
    v2013调试无法访问此网站 localhost 拒绝了我们的连接请求
    随机不重复流水号。
    通过location对象的某些属性得到一个完整URL的各个部分。
    Vue.JS学习笔记
    前端名词录
    React学习札记一
    kraken-ejs创建一个项目【学习札记】
    express 学习札记
    nth-child & nth-of-type区别
  • 原文地址:https://www.cnblogs.com/wukc/p/13717121.html
Copyright © 2020-2023  润新知