【发布时间】:2019-02-22 02:38:04
【问题描述】:
我正在尝试获取包含土耳其字符的标题值,例如“ı,ğ,ü,ş,ö,ç”。我尝试将 ISO-8859-1 编码支持添加到 Spring Boot 配置中,但未能成功。这是application.properties文件内容
spring.http.encoding.charset=ISO-8859-1
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.http.encoding.force-request=true
spring.http.encoding.force-response=true
这是一个示例 post 映射,它以 name 参数作为请求标头。
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SampleController {
@PostMapping(value = "/api/hello", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> samplePost(@RequestHeader("name") String name) {
System.out.println("name : " + name);
return ResponseEntity.ok("Hello " + name);
}
}
您可以在下面找到示例 curl 和 System.out.println 结果
卷曲:
curl -X POST http://127.0.0.1:8080/api/hello -H 'Accept: application/json' -H 'Content-Type: application/json; charset=UTF-8' -H 'name: ığüşöç'
输出:
name : ıÄüÅöç
有什么想法吗?
【问题讨论】:
标签: spring spring-boot encoding