美文网首页
curl模拟Postman发送HTTP请求

curl模拟Postman发送HTTP请求

作者: 康俊1024 | 来源:发表于2019-08-13 21:37 被阅读0次

    前言

    一般情况,我们调试数据接口,都会使用 Postman 这个工具,但是在线上Linux环境,比较麻烦。在命令行中,我们可以使用 curl 这个工具,满足我们轻量的调试要求。

    curl GET 请求

    curl命令 + 请求接口的地址。

    curl http://www.jianshu.com/login.cgi?user=kangjun&password=123456
    

    curl POST 请求

    我们可以用 -X POST 来申明我们的请求方法,用 -d 参数,来传送我们的参数。所以,我们可以用 -X PUT 和 -X DELETE 来指定另外的请求方法。

    curl http://www.jianshu.com/login -X POST -d "title=comewords&content=articleContent"
    

    如上,这就是一个普通的 post 请求。
    但是,一般我们的接口都是 json 格式的。我们可以用 -H 参数来申明请求的 header

    curl http://www.jianshu.com/login -X POST -H "Content-Type:application/json" -d "{title=comewords&content=articleContent}"
    

    相关文章

      网友评论

          本文标题:curl模拟Postman发送HTTP请求

          本文链接:https://www.haomeiwen.com/subject/ffdijctx.html