我想在我的应用程序中接收自定义标题Date。下面是我的代码
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests().antMatchers(HttpMethod.POST, "/data/**").authenticated().and()
.addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class)
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
获取标题的代码
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
Enumeration<String> ss = request.getHeaderNames();
while (ss.hasMoreElements()) {
String string = (String) ss.nextElement();
System.out.println(string);
}
System.out.println(request.getDateHeader("date"));
}
输出:
host
connection
content-length
accept
origin
x-requested-with
user-agent
content-type
referer
accept-encoding
accept-language
cookie
-1
请求:
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Date: Mon, 07 Jan 2019 13:46:52 GMT' {"type":"formData"} 'http://localhost:8080/data'
我想接收我传递的日期标头,但没有收到。是什么阻止了额外的标题?
答案 0 :(得分:1)
我认为标题名称存在问题,因为它可能是保留键
日期
尝试使用其他一些随机标头名称,然后检查是否可行。