akka http、字符集 header、utf-8 问题
akka http, charset header, utf-8 issue
我有这条路线:
path("rus") {
complete("Привет!")
}
当我使用浏览器访问 /rus (chrome) 时,我得到以下输出:
"Привет!"
为什么?响应 header 是:
HTTP/1.1 200 OK
Server: akka-http/2.4.10
Date: Mon, 10 Oct 2016 22:31:53 GMT
Content-Type: application/json
Content-Length: 15
我以前用 spray,但现在我想要 akka http,我没有遇到过这样的问题。
当我卷曲这条路径时,我得到正常输出
$ curl http://localhost:9010/rus
"Привет!"
我看到响应 header 'Content-Type' 应该是 'application/json;charset=utf-8' 但缺少字符集...
我找到了 withParams 方法。现在可以使用了
HttpEntity(ContentType(MediaTypes.`application/json`.withParams(Map("charset" -> "utf-8"))), "Привет".getBytes("UTF-8"))
很遗憾,这是 a bug in chromium. The charset
parameter must be ignored for the application/json
content-type according to its IANA registration:
Note: No "charset" parameter is defined for this registration.
Adding one really has no effect on compliant recipients.
我有这条路线:
path("rus") {
complete("Привет!")
}
当我使用浏览器访问 /rus (chrome) 时,我得到以下输出:
"Привет!"
为什么?响应 header 是:
HTTP/1.1 200 OK
Server: akka-http/2.4.10
Date: Mon, 10 Oct 2016 22:31:53 GMT
Content-Type: application/json
Content-Length: 15
我以前用 spray,但现在我想要 akka http,我没有遇到过这样的问题。
当我卷曲这条路径时,我得到正常输出
$ curl http://localhost:9010/rus
"Привет!"
我看到响应 header 'Content-Type' 应该是 'application/json;charset=utf-8' 但缺少字符集...
我找到了 withParams 方法。现在可以使用了
HttpEntity(ContentType(MediaTypes.`application/json`.withParams(Map("charset" -> "utf-8"))), "Привет".getBytes("UTF-8"))
很遗憾,这是 a bug in chromium. The charset
parameter must be ignored for the application/json
content-type according to its IANA registration:
Note: No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients.