Spring boot 无法发送包含某些特殊字符的请求,如ß;
当我发送POST请求时,body请求包含一些特殊字符,如ß,实际上它在德语中是一个字符,如“Zentrale BußGeldtelle”。下面是我使用Gitbash上的curl run发送的请求的信息:Spring boot 无法发送包含某些特殊字符的请求,如ß;,spring-boot,character-encoding,Spring Boot,Character Encoding,当我发送POST请求时,body请求包含一些特殊字符,如ß,实际上它在德语中是一个字符,如“Zentrale BußGeldtelle”。下面是我使用Gitbash上的curl run发送的请求的信息: curl --location --request POST 'http://localhost:8080/user/v1/register' \ --header 'Content-Type: application/json' \ --data-raw '{ "userna
curl --location --request POST 'http://localhost:8080/user/v1/register' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "ßtest",
"password": "P@ssword"
}'
我得到的错误请求状态如下:
{
"timestamp":"2020-06-27T05:22:50.676+0000",
"status":400,
"error":"Bad Request",
"message":"JSON parse error: Invalid UTF-8 middle byte 0x74\n at [Source: (PushbackInputStream);
line: 1, column: 18]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid UTF-8 middle byte 0x74\n at [Source: (PushbackInputStream); line: 1, column: 18]\n at [Source: (PushbackInputStream); line: 1, column: 15] (through reference chain: com.example.springlogin.dto.UserDto[\"username\"])",
"path":"/user/v1/register"
}
我认为这与我的性格有关。但是当我使用postman发送请求时,问题并没有出现。我使用Springboot实现了该api
所以任何人都可以帮我解决上述问题。提前感谢尝试将charset=utf-8添加到内容类型感谢您的快速响应,已经添加但仍然得到相同的IsSueCheck感谢所有人的响应。经过调查和调试。根本原因实际上是消费者使用了错误的编码(不是utf-8)。最终的解决方案是从用户端使用utf-8。请将其发布为并回答并接受,以便其他人也能从中受益!尝试将charset=utf-8添加到内容类型感谢您的快速响应,已经添加但仍然得到相同的IsSueCheck感谢所有人的响应。经过调查和调试。根本原因实际上是消费者使用了错误的编码(不是utf-8)。最终的解决方案是从用户端使用utf-8。请将其发布为并回答并接受,以便其他人也能从中受益!