如何查看查詢字元串?→輸入包含查詢字元串的URL,比如:http://localhost:54176/api/ProductCategories?name=darren&age=25→點擊Params,查詢字元串以鍵值隊集合的形式存儲→選中鍵值對,右鍵選擇"EncodeURIComponent"可以
如何查看查詢字元串?
→輸入包含查詢字元串的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