英文:
Xml tags printing differently in Restcontroller
问题
@PostMapping(value = "/HttpNoRespAdapter", consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE, MediaType.APPLICATION_XML_VALUE }, produces = MediaType.APPLICATION_XML_VALUE)
protected String process(@RequestBody String request, HttpServletResponse response) {
}
我正在使用控制器进行Spring中的Post映射。
我正在将请求体中的内容作为字符串进行处理,应该是以下的XML内容:
<REQ><FEATURE>DELIVERY-RECEIPT</FEATURE><TIME-STAMP><![CDATA[20200925190730]]></TIME-STAMP><TRANSACTION-ID><![CDATA[71554]]></TRANSACTION-ID><SMPP-ID><![CDATA[airtel]]></SMPP-ID><COMMAND-ID><![CDATA[5]]></COMMAND-ID><OA><![CDATA[8407600010]]></OA><DA><![CDATA[555]]></DA><DCS><![CDATA[0]]></DCS><SMS><![CDATA[stat:DELIVRD err:000 Text:silent]]></SMS><MESSAGE-ID><![CDATA[19]]></MESSAGE-ID></REQ>
但实际得到的结果是:
%3CREQ%3E%3CFEATURE%3EDELIVERY-RECEIPT%3C%2FFEATURE%3E%3CTIME-STAMP%3E%3C%21%5BCDATA%5B20201007175019%5D%5D%3E%3C%2FTIME-STAMP%3E%3CTRANSACTION-ID%3E%3C%21%5BCDATA%5B60564%5D%5D%3E%3C%2FTRANSACTION-ID%3E%3CSMPP-ID%3E%3C%21%5BCDATA%5Bairtel%5D%5D%3E%3C%2FSMPP-ID%3E%3CCOMMAND-ID%3E%3C%21%5BCDATA%5B5%5D%5D%3E%3C%2FCOMMAND-ID%3E%3COA%3E%3C%21%5BCDATA%5B8007600010%5D%5D%3E%3C%2FOA%3E%3CDA%3E%3C%21%5BCDATA%5B555%5D%5D%3E%3C%2FDA%3E%3CDCS%3E%3C%21%5BCDATA%5B0%5D%5D%3E%3C%2FDCS%3E%3CSMS%3E%3C%21%5BCDATA%5Bid%3A69+sub%3A001+dlvrd%3A001+submit+date%3A2010071750+done+date%3A2010071750+stat%3ADELIVRD+err%3A000+Text%3Asilent%5D%5D%3E%3C%2FSMS%3E%3CMESSAGE-ID%3E%3C%21%5BCDATA%5B69%5D%5D%3E%3C%2FMESSAGE-ID%3E%3C%2FREQ%3E=
XML标签被错误地替换了。您应该如何纠正这个问题?
英文:
I am using a controller for post mapping in spring
@PostMapping(value ="/HttpNoRespAdapter",consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE, MediaType.APPLICATION_XML_VALUE}, produces=MediaType.APPLICATION_XML_VALUE)
protected String process(@RequestBody String request, HttpServletResponse response) {
}
I am taking whatever coming in the requestbody as string, the following xml should come
<REQ><FEATURE>DELIVERY-RECEIPT</FEATURE><TIME-STAMP><![CDATA[20200925190730]]></TIME-STAMP><TRANSACTION-ID><![CDATA[71554]]></TRANSACTION-ID><SMPP-ID><![CDATA[airtel]]></SMPP-ID><COMMAND-ID><![CDATA[5]]></COMMAND-ID><OA><![CDATA[8407600010]]></OA><DA><![CDATA[555]]></DA><DCS><![CDATA[0]]></DCS><SMS><![CDATA[stat:DELIVRD err:000 Text:silent]]></SMS><MESSAGE-ID><![CDATA[19]]></MESSAGE-ID></REQ>
But it coming as
%3CREQ%3E%3CFEATURE%3EDELIVERY-RECEIPT%3C%2FFEATURE%3E%3CTIME-STAMP%3E%3C%21%5BCDATA%5B20201007175019%5D%5D%3E%3C%2FTIME-STAMP%3E%3CTRANSACTION-ID%3E%3C%21%5BCDATA%5B60564%5D%5D%3E%3C%2FTRANSACTION-ID%3E%3CSMPP-ID%3E%3C%21%5BCDATA%5Bairtel%5D%5D%3E%3C%2FSMPP-ID%3E%3CCOMMAND-ID%3E%3C%21%5BCDATA%5B5%5D%5D%3E%3C%2FCOMMAND-ID%3E%3COA%3E%3C%21%5BCDATA%5B8007600010%5D%5D%3E%3C%2FOA%3E%3CDA%3E%3C%21%5BCDATA%5B555%5D%5D%3E%3C%2FDA%3E%3CDCS%3E%3C%21%5BCDATA%5B0%5D%5D%3E%3C%2FDCS%3E%3CSMS%3E%3C%21%5BCDATA%5Bid%3A69+sub%3A001+dlvrd%3A001+submit+date%3A2010071750+done+date%3A2010071750+stat%3ADELIVRD+err%3A000+Text%3Asilent%5D%5D%3E%3C%2FSMS%3E%3CMESSAGE-ID%3E%3C%21%5BCDATA%5B69%5D%5D%3E%3C%2FMESSAGE-ID%3E%3C%2FREQ%3E=
the xmltags are been replaced wrongly. how can i rectify this??
答案1
得分: 1
尝试使用java.net.URLDecoder:
request = URLDecoder.decode(request, "UTF-8");
英文:
Try to use java.net.URLDecoder:
request = URLDecoder.decode(request, "UTF-8");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论