0
我的代码是getResponseBodyAsStream返回 “1字节UTF-8序列的无效字节1”
PostMethod method = new PostMethod(TRANSLATION_SERVICE);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(method.getResponseBodyAsStream());
它产生1字节的
无效字节1 UTF-8序列
当我使用method.getResponseBodyAsString()
,我得到预期的回应,但the API明确指出
注意:这将导致整个响应主体缓冲在内存中。恶意服务器可能很容易耗尽所有虚拟机内存。强烈建议,如果响应的内容长度未知或相当大,则使用getResponseAsStream。
是否有替代上述方法?