【发布时间】:2013-11-01 17:46:26
【问题描述】:
当我尝试在 java 中使用 spring 时,我得到了一个 HttpMessageNotReadableException。 打印的 Stacktrace 说:
嵌套异常是 org.springframework.http.converter.HttpMessageNotReadableException:无法读取 JSON:非法字符((CTRL-CHAR,代码 31)):只允许常规空格(\r、\n、\t)标记之间
这与我获取的方式有关,还是与我的回复格式有关?
我的称呼是:
HttpEntity<JSONObject> entity = new HttpEntity<JSONObject>();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Accept", "application/x-gzip");
headers.set("charset", "UTF-8");
return getConnector().exchange(url, HttpMethod.GET, entity, JSONObject.class);
getConnector() 返回一个 RestConnector
响应标头包括: 内容编码:gzip 内容类型:application/json
不知道是不是和gzip的编码有关
编辑: 问题是内容编码是gzip..最后,我使用了支持gzip编码的HttpClient
【问题讨论】: