我一直试图让 WS 向 json api 发出请求。到目前为止,我无法让 utf-8 正确呈现,记录在这里:Play Framework WS lost unicode chars from external api
我现在正在尝试将字符集添加到请求的 http 标头中。但是,我似乎无法做到这一点。如果我运行以下命令:
val request = ws.url("http://myserver.org")
request.withHttpHeaders("charset" -> "utf-8")
println("request headers: " request.headers)
request.get().map { response =>
println("response headers: " + response.headers)
...
这将生成以下内容:
request headers: Map()
response headers: Map(Date -> Buffer(Tue, 07 Nov 2017 20:11:58 GMT), Server -> Buffer(Jetty(8.1.5.v20120716)), Content-Type -> Buffer(application/json), Cache-Control -> Buffer(private, must-revalidate, max-age=0), Content-Length -> Buffer(9822), X-Content-Type-Options -> Buffer(nosniff))
谁能诊断我做错了什么?为什么请求标头映射为空?我遵循了 2.6 scala doc的约定