使用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)接口获取的数据如下: