美文网首页
curl 发送 http请求

curl 发送 http请求

作者: M_豆 | 来源:发表于2019-02-15 14:05 被阅读0次

测试接口,经常会用到接口测试工具如postman,而curl命令可以直接在终端进行测试,下面介绍一下如何使用

get 请求

curl "http://localhost:3000/api/books?page=1&limit=4" 

post请求   

curl -X POST "http://localhost:3000/api/books"  -d "name=测试"

-X POST 表示请求方式,-d 后边是请求参数 ,put、delete请求同post请求

请求参数为json格式

curl -H "Content-Type:application/json" -X POST "http://localhost:3000/api/books" -d {\"name\":\"测试\"}

返回json格式化问题

curl请求没有格式化之前是这样的

用npm安装json命令  npm install -g json

在curl命令后面添加 | json 即可。

curl "http://localhost:3000/api/warehouse?page=1&limit=4" -s | json

相关文章

  • REST调试工具

    CURL 发送GET请求 curl -H "Accept:application/json" http://loc...

  • 发送http请求

    发送http请求 发送http2请求 参考链接:curl支持h2: https://segmentfault.co...

  • Curl发送HTTP请求

    大家好,我是IT修真院深圳分院第01期学员,一枚正直纯洁善良的web程序员。今天给大家分享一下,修真院官网JAVA...

  • curl 发送 http请求

    测试接口,经常会用到接口测试工具如postman,而curl命令可以直接在终端进行测试,下面介绍一下如何使用 ge...

  • 后端单元测试

    如何测试 api 1. 使用 curl 命令 发送 GET 请求curl http://localhost:300...

  • php发送http请求,获取网页内容方法

    PHP发送http请求,获取网页内容方法:cURL、file_get_contents()、fopen() 区别:...

  • HTTP请求和响应格式

    分析请求 curl 发请求,得到响应- curl -L http://baidu.com- curl http:/...

  • 通过curl来发送HTTP请求

    简介 curl命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但...

  • php 使用curl发送http请求

  • curl模拟Postman发送HTTP请求

    前言 一般情况,我们调试数据接口,都会使用 Postman 这个工具,但是在线上Linux环境,比较麻烦。在命令行...

网友评论

      本文标题:curl 发送 http请求

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