I can not make request encoding to work correctly. For encoding to work, i added filter to spring security:
@Bean
public CharacterEncodingFilter characterEncodingFilter() {
CharacterEncodingFilter filter = new CharacterEncodingFilter();
filter.setEncoding("UTF-8");
filter.setForceEncoding(true);
return filter;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(characterEncodingFilter(), CsrfFilter.class);
...
}
Add meta to my pages:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
...
Add UriEnconding to tomcat 8:
<Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8"
connectionTimeout="20000"
redirectPort="8443" />
But it is not responding to none of them. When i send a request and debug it, the result is wrong. For example when i send بای
as a part of request form, i recieve باÛ
as result. Is there any part of config i am missing?
When sending payload ajax request (with rest client and ofcource to another method) it workes correctly, but no luck with form data. My controller looks like this:
@RequestMapping(value = "/test1")
@ResponseBody
public String test1(@RequestBody String req) {
return req;
}
@RequestMapping(value = "/test2")
@ResponseBody
public String test2(@RequestParam("search") String req) {
return req;
}
different tries:
- for test1 with
Content-Type=application/json
it correctly recieves the parameter. - for test2 with
Content-Type=application/x-www-form-urlencoded
and get method, again everything works great. - for test2 with
Content-Type=application/x-www-form-urlencoded
and POST method, it returns wrong encoded values.
It seems the problem is with POST method only. any suggestions?