开发者

getResponseBodyAsStream returns "Invalid byte 1 of 1-byte UTF-8 sequence"

My code is

PostMethod method = new PostMethod(TRANSLATION_SERVICE);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(method.getResponseBodyAsStream());

It produces

Invalid byte 1 of 1-byte UTF-8 sequence

When I use method.开发者_StackOverflow社区getResponseBodyAsString(), I get the desired response, but the API clearly states that

Note: This will cause the entire response body to be buffered in memory. A malicious server may easily exhaust all the VM memory. It is strongly recommended, to use getResponseAsStream if the content length of the response is unknown or resonably large.

Is there an alternative to the above approach?


Content you are reading claims to use UTF-8 encoding, but does not (probably uses LATIN-1 or windows default encoding): that is, XML document is question is broken; or service you calling is returning incorrect encoding definition. Either way, service is returning you invalid information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜