我在生成 PNG 图像响应的方法时遇到问题。
@RequestMapping(value = "/thumb/{id}.png", produces = "image/png")
@ResponseBody
public char[] thumb(@PathVariable UUID id)
{
// action logic here
return CatalogController.PLACEHOLDER_THUMB;
}
但是我无法访问此操作 - 它已正确执行(我在数据库中看到逻辑效果),但客户端收到406 Not Acceptable。
以下是我模拟请求的方法(Chrome 和 Internet Explorer 中也会发生同样的情况):
$ wget "http://localhost:8080/thumb/13164e6b-fc0f-4c67-a7d3-e2c56224384b.png" -O - --header="Accept: image/png"
--2013-11-18 18:37:30-- http://localhost:8080/thumb/13164e6b-fc0f-4c67-a7d3-e2c56224384b.png
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... connected.
HTTP request sent, awaiting response... 406 Not Acceptable
2013-11-18 18:37:30 ERROR 406: Not Acceptable.
编辑
以下是浏览器中显示的更详细说明:
description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().
最佳答案
好的,感谢大家的帮助,但答案要简单得多 - 根本不可能使用 char[]
作为响应内容。
切换到byte[]
,一切正常!
(可能可以为 byte[]
注册处理程序,但我不需要,因此无法确认)。
关于java - 生成 PNG 响应时出现错误 406 Not Acceptable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20053384/