简介
REST Client 堪比是 Postman的替代品。REST Client 是一个 VS Code 扩展插件,可以通过写脚本的形式发送 HTTP 请求并直接在 VS Code 上查看响应结果。这样不仅能看到http的测试结果,测试的脚本文件还能得以保留。
参考:
[VSCode插件推荐] REST Client: 也许是比Postman更好的选择
下载
1、新建文件,后缀以 .http 或者 .rest 结尾
2、注意两条HTTP请求脚本之间一定要 ### 分隔
测试一 : .http文件
新建文件 : test1.http
@BASE_URL = https://httpbin.org
### 发送JSON数据
POST {{BASE_URL}}/post
Content-Type: application/json
//这里必须有一空行
{
"query": {"a":1,"b":2}
}
### post:application/json使用curl
curl -X POST
{{BASE_URL}}/post
-H "Content-Type:application/json"
-d '{"query": {"a":2,"b":1}}'
测试二 : .rest文件
新建文件 : wanandroid.rest
# 注意不带引号
@BASE_URL = https://www.wanandroid.com
### 获取公众号列表
GET {{BASE_URL}}/wxarticle/chapters/json
### 查看某个公众号历史数据
GET {{BASE_URL}}/wxarticle/list/408/1/json
#######################################################################
#################################GET请求################################
### 按照作者昵称搜索文章
GET {{BASE_URL}}/article/list/0/json?author=鸿洋
### 按照作者昵称搜索文章,使用curl命令
curl -X GET {{BASE_URL}}/article/list/2/json?author=鸿洋
#######################################################################
#######################################################################
### 注册
POST {{BASE_URL}}/user/register
Content-Type: application/x-www-form-urlencoded
username=ablexq1&password=xq123456&repassword=xq123456
#######################################################################
###########POST请求application/x-www-form-urlencoded####################
### 登录
POST {{BASE_URL}}/user/login
Content-Type: application/x-www-form-urlencoded
username=ablexq&password=xq123456
### 登录:post : application/x-www-form-urlencoded 使用curl
curl -X POST
{{BASE_URL}}/user/login
-H "Content-Type:application/x-www-form-urlencoded"
-d "username=ablexq1&password=xq123456"
#######################################################################
#######################################################################
### 退出
GET {{BASE_URL}}/user/logout/json