使用Postman Interceptor插件解决REST客户端的post请求的CSRF

来源:互联网 发布:在线制作淘宝店招 编辑:程序博客网 时间:2024/06/05 11:29



1、Postman Interceptor使用方法:

http://www.cnplugins.com/devtool/postman-interceptor/detail.html

2、springmvc-show-case的CSRF例子,get请求返回的<head>部分:

<!--
Used for including CSRF token in JSON requests
Also see bottom of this file for adding CSRF token to JQuery AJAX requests
-->
        <meta name="_csrf" content="2e4dfa84-c29d-430f-800a-974421a93496"/>
        <meta name="_csrf_header" content="X-CSRF-TOKEN"/>


3、打开postman的Interceptor开关,设置post请求的头部:

X-CSRF-TOKEN : 2e4dfa84-c29d-430f-800a-974421a93496

设置post请求的body:

adadfa,随便一个字符串


url:http://122.0.0.1:9123/spring-mvc-showcase/data/body


@RequestMapping(value="body", method=RequestMethod.POST)
public @ResponseBody String withBody(@RequestBody String body) {
return "Posted request body '" + body + "'";
}