You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XAgent中ServletInputStream的read方法始终返回-1,无法读取POST内容

问题:Domino XAgent无法读取POST请求内容

我在使用以下XPage/XAgent时无法读取POST内容:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" rendered="false"
    viewState="nostate" xmlns:xe="http://www.ibm.com/xsp/coreex">
    <xp:this.beforeRenderResponse>
        <![CDATA[#{javascript:
            var xagentprocessor = new com.my.test.XagentProcessor;  
            xagentprocessor.process();
        }]]>
    </xp:this.beforeRenderResponse>
</xp:view>

该XAgent运行以下代码,目的是将提交的数据回显到浏览器:

public class XagentProcessor {
    public void process() {
        try {
            byte[] body = Util.getPostRequestBytes();
            Util.sendResponseBytes(body);
        } catch (Exception e) {
            System.out.println("Error in XagentProcessor process() method:"+e.toString());
        }
    }
}

上述代码调用了工具类中的静态方法:

public static byte[] getPostRequestBytes() {
        HttpServletRequest request = getHttpRequest();
        try {
            ServletInputStream is = request.getInputStream();
            int length=request.getContentLength(); //This is definitely nonzero
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            int nRead;
            byte[] data = new byte[16384];
            while ((nRead = is.read(data, 0, data.length)) != -1) {
              buffer.write(data, 0, nRead);
            }
            return buffer.toByteArray();
        } catch (IOException e) {
            System.out.print("Error in Util.getPostRequestText() method:" + e.toString());
        }
        return new byte[0];
    }

我的问题是,该方法返回空内容,第一次读取ServletInputStream就返回-1。我猜测这是因为Domino提前读取了输入流来检查$$viewid字段,导致getPostRequestBytes方法无法再读取流内容。

目前我的思路是要么重新读取流(但我认为这不可行),要么让Domino不读取流来检查$$viewid字段,但现在毫无头绪,恳请大家提供帮助!


内容的提问来源于stack exchange,提问作者Adam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 09:50:17