zoukankan      html  css  js  c++  java
  • Linux 常用命令

    将接口返回结果保存成文件

    为了快速方便查看 curl 的请求结果(通常是 json),需要将 curl 的结果保存下来

    可以用 -o output.json 或者 >> output.json 实现

    curl --location --request GET 'https://randomuser.me/api/?results=5' -o output.json
    curl --location --request GET 'https://randomuser.me/api/?results=5' >> output.json
    

    查看接口返回是否有某个字符串

    有的时候为了判断接口是否生效,需要查看接口返回里是否有某个字段,可以用 grep

    # 接口返回是否有 medium 
    curl --location --request GET 'https://randomuser.me/api/?results=5' | grep medium
    

    curl 结果格式化查看(jq)

    前面说到可以用 grep 快速查看返回结果是否包含某个字符串,如果需要详细查看返回结果,可以用 jq(brew install jq)

    # 格式化返回结果
    curl --location --request GET 'https://randomuser.me/api/?results=5' | jq
    
    # 查看返回结果的 .info 字段
    curl --location --request GET 'https://randomuser.me/api/?results=5' | jq .info
    
    # 支持数组查看,记得要用 引号 引起来
    curl --location --request GET 'https://randomuser.me/api/?results=5' | jq '.results[0].name'
    
  • 相关阅读:
    常见设备标记长度查询
    word怎么在方框中打对号
    shell dict 操作
    词表数据转换
    GoLand tool tips
    mac使用技巧
    人生三大陷阱
    【js重学系列】执行上下文
    uniapp-ui库
    【js重学系列】instanceof
  • 原文地址:https://www.cnblogs.com/lessfish/p/14465475.html
Copyright © 2011-2022 走看看