【发布时间】:2011-12-06 23:15:57
【问题描述】:
我正在尝试使用使用块编码的 REST 服务读取一些信息。
String encodedURL = URLEncoder.encode(url, "UTF-8");
WebClient client = org.apache.cxf.jaxrs.client.WebClient.create(encodedURL).accept("text/html");
Response response = client.get();
响应包含状态、元数据和实体。元数据包含以下信息:
{Date=[Thu, 13 Oct 2011 13:27:02 GMT], Vary=[Accept-Encoding, User-Agent], Transfer-Encoding=[chunked], Keep-Alive=[timeout=15, 最大=100],内容类型=[文本/html;字符集=字符集=UTF-8], Connection=[Keep-Alive], X-Pad=[避免浏览器错误], 服务器=[Apache/2.2.3 (Linux/SUSE)]}
并且该实体包含 sun.net.www.protocol.http.HttpURLConnection$HttpInputStream 类型的实例。
我过去,一直使用下面这行代码,来获取整个结果字符串:
String resultString = client.get(String.class);
但不知何故,这一行抛出了一个异常:
.读取响应消息时出现问题,类:类 java.lang.String,ContentType:文本/html;charset=charset=UTF-8。 org.apache.cxf.jaxrs.client.ClientWebApplicationException:.Problem 阅读响应消息,类:类 java.lang.String, 内容类型:文本/html;charset=charset=UTF-8。
...引起:
引起:java.io.UnsupportedEncodingException: charset=UTF-8 at sun.nio.cs.StreamDecoder.forInputStreamReader(Unknown Source) at java.io.InputStreamReader.(未知来源)在 org.apache.cxf.helpers.IOUtils.toString(IOUtils.java:180) 在 org.apache.cxf.helpers.IOUtils.toString(IOUtils.java:166) 在 org.apache.cxf.jaxrs.provider.PrimitiveTextProvider.readFrom(PrimitiveTextProvider.java:51) 在 org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:435) ... 49 更多
是否有直接的解决方案来获取响应的全部内容?
谢谢!
关
【问题讨论】:
标签: java rest encoding chunked