展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

测试接口

curl

# 下载后直接解压
# 环境配置:
  CURL_HOME = C:\app\curl\curl-7.66.0
# 在path中添加
  %CURL_HOME%\bin\
# cmd验证:curl --version

# get请求
curl localhost:8080/test?name=goudan

# post请求
curl localhost:8080/addUser -X POST -d "name=goudan&age=18"

# post请求,传递json
curl localhost:8080/getUsers -X POST -H "Content-Type:application/json" -d '{"name":"goudan","age":"18"}'

# post请求,上传文件:`将D:\doc\test.png上传到127.0.0.1:8090/log/upload接口`
curl localhost:8090/log/upload -F "file=@/doc/test.png" -H "token: test" -v

# 自定义请求头
curl --header "Content-Type:application/json" http://example.com

# 显示通信过程:使用 `-v`参数可以显示一次http通信的整个过程,包括端口连接和http request头信息

浏览器插件

  • Edge浏览器安装插件
  • 测试

idea

vscode

  • 参考
  • vscode安装插件REST Client,项目根路径下新建stock.http,编写url和请求体,点击Send Request,右侧显示返回数据
# https://marketplace.visualstudio.com/items?itemName=humao.rest-client

GET https://example.com/comments/1 HTTP/1.1

POST http://dummy.restapiexample.com/api/v1/create HTTP/1.1
content-type: application/json
{
    "name":"Hendry",
    "salary":"61888",
    "age":"26"
}

# token
POST https://example.com/comments HTTP/1.1
Authorization: token xxx

# 身份验证
GET https://httpbin.org/basic-auth/user/passwd HTTP/1.1
Authorization: Basic username:password

# 请求变量
@baseUrl = https://example.com/api
@authToken = {{login.response.headers.X-AuthToken}}

// 一个http文件中还可以支持多个接口请求,只需 ### 隔开即可

posted @ 2022-06-09 07:59  DogLeftover  阅读(27)  评论(0编辑  收藏  举报