使用postman時,如果項目開啟了csrf防護,需要在請求的header中加入“X-CSRFToken”,
和在Tests上加上請求csrftoken的代碼才可以用postman發出請求,操作如下:
1)header頭部分別加入Content-Type(根據實際情況設置)和x-csrf-token,如下圖:
2)Tests設置相關代碼,如下:
Tests代碼如下:
var csrf_token = postman.getResponseCookie("csrftoken").value postman.clearGlobalVariable("csrftoken"); postman.setGlobalVariable("csrftoken", csrf_token);
3)設置完上面說的,然后就可以請求接口獲取參數了,輸入接口url和在Body里設置請求接口的參數,如下:
4)接口獲取的數據如下: