注意:本次舉例的網站登錄接口是不限制Content-Type,所以可以application/x-www-from-urlencoded或application/json。
- 在JMeter使用Parameters【參數】時,Content-Type默認爲application/x-www-from-urlencoded,可以不傳;
Parameters【參數】的數據以鍵值對的形式發送請求,具體表現爲鍵=值,以”&“分割參數,如:鍵1=值1&鍵2=值2&鍵3=值3
按照下圖依次說明:
- HTTP請求 設置Parameters【參數】爲鍵值對的數據形式
- 觀察結果樹 查看到請求的Request Body的POST data 確實是以鍵值對(鍵1=值1&鍵2=值2&鍵3=值3)的數據形式發送請求
- 觀察結果樹 查看到請求的Request Headers 的content-type確實是默認的content-type:application/x-www-from-urlencoded
- 觀察結果樹 查看到響應數據的Response Body 顯示請求有正確的響應
- 在JMeter使用Body Data【消息體數據】時,若輸入參數是json數據格式,Content-Type只能傳application/json;
按照下圖依次說明:
- HTTP信息頭管理器 設置header的content-type:application/json
- HTTP請求 設置Body Data【消息體數據】爲json數據格式
- 觀察結果樹 查看到請求的Request Body的POST data 確實是以json形式發送請求
- 觀察結果樹 查看到請求的Request Headers 的content-type確實是在HTTP信息頭管理器 設置header的content-type一樣是application/json
- 觀察結果樹 查看到響應數據的Response Body 顯示請求有正確的響應
- 在JMeter使用Body Data【消息體數據】時,輸入的數據是鍵值對的形式(如:type=username&accounts=jmUser05&pwd=123456),Content-Type只能傳application/x-www-from-urlencoded
按照下圖依次說明:
- HTTP信息頭管理器 設置header的content-type:application/x-www-from-urlencoded
- HTTP請求 設置Body Data【消息體數據】爲鍵值對的形式
- 觀察結果樹 查看到請求的Request Body的POST data 確實是以鍵值對的形式發送請求
- 觀察結果樹 查看到請求的Request Headers 的content-type確實是在HTTP信息頭管理器 設置header的content-type一樣是application/x-www-from-urlencoded
- 觀察結果樹 查看到響應數據的Response Body 顯示請求有正確的響應