验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

Linux的curl指令如何使用

阅读:865 来源:乙速云 作者:代码code

Linux的curl指令如何使用

      Linux的curl指令使用

      curl指令发送GET请求

      格式如下:

      curl -H [header参数] -XGET URL

      假设URL地址为:http://localhost:8001/test,GET请求,参数为startTime,endTime

      1、header传多个参数

      1)可以用多个-H传多个header参数,如下:

      curl -H "token:122212eee23" -H "id:123456" -XGET http://localhost:8001/test

      或者 curl -H "token:122212eee23" -H "id:123456" http://localhost:8001/test

      2)-H 后面接的header参数,每个参数占一行,也可以传多个参数,如下:

      curl -H "token:122212eee23
      id:123456"  http://localhost:8001/test

      2、GET请求传参(容易出错的地方,亲测)

      1)&前面加字符取消转义,如下:

      curl -H "token:122212eee23" -H "id:123456"
      -XGET http://localhost:8001/test?startTime=20220215000000&endTime=20220215235959

      2)URL加上双引号

      curl -H "token:122212eee23" -H "id:123456"
      -XGET "http://localhost:8001/test?startTime=20220215000000&endTime=20220215235959"

      curl指令发送POST请求

      格式如下:

      curl -H[header参数,多个参数用多个-H隔开] -X POST -d '参数列表' URL

      如下例子:假设URL为:http://localhost:8080/api

      curl -H "Content-Type: application/json" -X POST -d '{"userId":1,"name":"学生"}' "http://localhost:8080/api"

      curl命令解读

      curl 是运维过程中常用的命令。常见的用途:测试地址url是否通畅;下载文件。

      为啥用来测试地址是否通畅?

      因为有时候某些场景下受到限制不能直接访问,比如:服务器上是没有桌面版的软件,如:postman、idea、浏览器,只有shell 命令行环境,这些情况需要用curl 命令去试探。但不包含你是真的很懒。

      下面是我自己遇到的场景:

      1、curl 请求 一个接口 看看通不通

      $ curl -H "Content-Type:application/json;charset=utf-8" -H "Authorization:123456789wertyuiosdfghjklxcvbn" http://192.168.xxx.xxx/xxxservice/api/v2/core/start?channel=

      -H:参数添加 HTTP 请求的标头,一个标头前面使用一个-H。

    分享到:
    *特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
    相关文章
    {{ v.title }}
    {{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
    你可能感兴趣
    推荐阅读 更多>