gpt4 book ai didi

java - 在 httpResponse 的正文中设置字符串

转载 作者:IT老高 更新时间:2023-10-28 21:10:35 25 4
gpt4 key购买 nike

我需要帮助。在我目前的开发中,其中一项要求是:

The server will return 200-OK as a response(httpresponse).

If the panelist is verified then as a result, the server must also return the panelist id of this panelist.

The server will place the panelist id inside the body of the 200-OK response in the following way:

<tdcp>

<cmd>

<ack cmd=”Init”>

<panelistid>3849303</panelistid>

</ack>

</cmd>

现在我可以将 httpresponse 设置为

httpServletResponse.setStatus(HttpServletResponse.SC_OK);

我可以放

String responseToClient= "<tdcp><cmd><ack cmd=”Init”><panelistid>3849303</panelistid></ack></cmd></tdcp>";

现在将上述 xml 放入 200-OK 响应的正文中是什么意思,如何实现?

最佳答案

您可以将 XML 直接写入响应,如下所示:

此示例使用 ServletResponse.getWriter(),即 PrintWriter 将字符串写入响应。

String responseToClient= "<tdcp><cmd><ack cmd=”Init”><panelistid>3849303</panelistid></ack></cmd></tdcp>";

httpServletResponse.setStatus(HttpServletResponse.SC_OK);
httpServletResponse.getWriter().write(responseToClient);
httpServletResponse.getWriter().flush();

关于java - 在 httpResponse 的正文中设置字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7658881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com