带有变音符号的curl会导致“JSON解析错误:无效的UTF-8中间字节0x22”

带有变音符号的curl会导致“JSON解析错误:无效的UTF-8中间字节0x22”

我从命令行(Windows 上的 Git Bash)或作为 Bash 脚本的一部分运行下面的 curl 命令。

curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d "{\"testField\":\"ä\"}" https://someurl...

卷曲命令的主体有一个元音变音 ä

作为在 AWS Elastic Beanstalk 容器中运行的 Spring Boot REST API 的服务器返回以下错误:

JSON parse error: Invalid UTF-8 middle byte 0x22; nested exception is com.fasterxml.jackson.core.JsonParseException: Invalid UTF-8 middle byte 0x22\n at [Source: (PushbackInputStream); line: 1, column: 17]

导入到 Postman 中的相同的curl 命令工作得很好,所以我相信这是一个curl 问题而不是服务器问题。

答案1

尝试ä用 UTF8 编码替换该字符\u00e4

curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"testField":"u00e4"}' https://someurl..

相关内容