XML标签在RestController中打印出现不同的格式。

huangapple go评论68阅读模式
英文:

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 =&quot;/HttpNoRespAdapter&quot;,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

&lt;REQ&gt;&lt;FEATURE&gt;DELIVERY-RECEIPT&lt;/FEATURE&gt;&lt;TIME-STAMP&gt;&lt;![CDATA[20200925190730]]&gt;&lt;/TIME-STAMP&gt;&lt;TRANSACTION-ID&gt;&lt;![CDATA[71554]]&gt;&lt;/TRANSACTION-ID&gt;&lt;SMPP-ID&gt;&lt;![CDATA[airtel]]&gt;&lt;/SMPP-ID&gt;&lt;COMMAND-ID&gt;&lt;![CDATA[5]]&gt;&lt;/COMMAND-ID&gt;&lt;OA&gt;&lt;![CDATA[8407600010]]&gt;&lt;/OA&gt;&lt;DA&gt;&lt;![CDATA[555]]&gt;&lt;/DA&gt;&lt;DCS&gt;&lt;![CDATA[0]]&gt;&lt;/DCS&gt;&lt;SMS&gt;&lt;![CDATA[stat:DELIVRD err:000 Text:silent]]&gt;&lt;/SMS&gt;&lt;MESSAGE-ID&gt;&lt;![CDATA[19]]&gt;&lt;/MESSAGE-ID&gt;&lt;/REQ&gt;

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, &quot;UTF-8&quot;);

huangapple
  • 本文由 发表于 2020年10月7日 20:29:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/64244071.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定