星空网 > 软件开发 > ASP.net

Postman测试Web API

 

如何查看查询字符串?

→输入包含查询字符串的URL,比如:http://localhost:54176/api/ProductCategories?name=darren&age=25
→点击Params,查询字符串以键值队集合的形式存储
→选中键值对,右键选择"EncodeURIComponent"可以对键或值加密


如何使用Body?

→form-data选项,输入表单数据
→x-www-form-urlencoded选项,输入表单数据,Postman自动加密
→raw选项,输入json数据

{
    "name":"",
    "username":""
    "age":25
}
→binary选项,上传图片、音频、视频等

这里准备了一些API需要测试:

GET     /categories
POST    /categories
PUT     /categories/{id}
GET     /categories/{id}
DELETE  /categories/{id}

POST    /categories/{id}/products
GET     /categories/{id}/products
DELETE  /categories/{id}/products/{productId}
GET     /categories/{id}/products/{productId}
PUT     /categories/{id}/products/{productId}


GET请求测试?

→点击No environment创建环境变量

host: http://localhost
port:8080

→GET请求

GET {{host}}:{{port}}/categories
GET {{host}}:{{port}}/categories/1
GET {{host}}:{{port}}/categories/1/products

POST请求测试?

■ 创建cateogory

==请求

POST {{host}}:{{port}}/categories

Headers:

Content-Type: application/json

Body:

{
    "name":""
}

==响应

status 201 created

{
    "id":"1",
    "name":"",
    "products":[]
}

■ 创建product


==请求

POST {{host}}:{{port}}/categories/1/products

Headers:

Content-Type: application/json

Body:

{
    "name":"",
    "features":["h","o"]
}

==响应

status 201 created

{
    "id":"1",
    "name":"",
    "features":["h","o"]
}


PUT请求测试?

==请求

PUT {{host}}:{{port}}/categories/1

Headers:

Content-Type: application/json

Body:

{
    "name":""
}

==响应

status 200 ok

{
    "message":""
}


DELET请求测试?


==请求

DELETE {{host}}:{{port}}/categories/1


==响应

{
    "message":""
}


Query parameters请求字符串测试?

==请求

GET {{host}}:{port}/categories/1/products?name=h

==响应

status 200 ok

[
    {
        "id":"1",
        "name":"h",
        "features":["h",...]
    },
    {
        "id":"1",
        "name":"h",
        "features":["h",...]
    }    
]

验证授权?

验证解决是谁的问题。授权解决能做什么的问题。

通常的情形是:

→ 输入用户名和密码

POST .../auth/login


Headers:

Content-Type: application/json

Body:

{
    "login":"",
    "password":""
}

→ 服务端返回token

在响应中获取到token

→ 再次请求在Headers中放入token

GET ../categories

Headers:

token:.....
Content-Type: application/json




原标题:Postman测试Web API

关键词:web

web
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

raise3d cn:https://www.goluckyvip.com/tag/24290.html
raitp:https://www.goluckyvip.com/tag/24291.html
Rakuten:https://www.goluckyvip.com/tag/24293.html
Rakuten Adverting:https://www.goluckyvip.com/tag/24294.html
Rakuten Ebates:https://www.goluckyvip.com/tag/24295.html
Rakuten Fulfillment Network:https://www.goluckyvip.com/tag/24296.html
船底顶攻略(船底顶最详细攻略):https://www.vstour.cn/a/411239.html
川藏线自驾游要怎么走才比较划算呢?:https://www.vstour.cn/a/411240.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流