在将RestTemplate用于XML响应时,响应中接收到无法读取的字符。下面是我的resttemplate配置。
torch.stack
这是我得到的答复。
RestTemplate restTemplate = new RestTemplateBuilder().basicAuthentication(userName, userPassword).build();
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
stringHttpMessageConverter.setWriteAcceptCharset(true);
for (int i = 0; i < restTemplate.getMessageConverters().size(); i++) {
if (restTemplate.getMessageConverters().get(i) instanceof StringHttpMessageConverter) {
restTemplate.getMessageConverters().remove(i);
restTemplate.getMessageConverters().add(i, stringHttpMessageConverter);
break;
}
}
我能够解析的共鸣是:
��]o�0��
ʤ�%�' ��eT�T:t�.�s��;�M)�~�h�M�s|��|;x�RW�g�� �Y��Z�T��o2�ayc'�8Nj/g���k:��P�����
������_���g�*Ϫ�n��컮��w���_0�;l3�4���+��0�Ufm%O�����Һ��'Q�s̕wa��jW�y0�7<H��n`�I��1-7����mch���0�J�V�at4�xk�&i(D W���Tb��b�����%F� r\r�c5�=�8r]�
0����"�F�=ǟ��v'���������T�XS���"}��
��b�����̔sI�]T3"I����mKߑ��;�5:�զƓM�J���K�x�8\G$�(ţp����p�i4
W�o��8���
���n>L�a��O�rHFe$�O�$.�� ���f���[J!��-8lL[��ޡ��E�<�Dۛ[P�v��c^�ㇱ� u�qr\qsx�y��3B�~P�OF���
我无法解析的响应是:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="urn:creditCard" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:creditCardResponse xmlns:ns1="urn:creditCard"><return xsi:type="tns:RPResponse">
<Status xsi:type="xsd:int">0</Status>
<ReferenceCode xsi:type="xsd:string">#xxxxx</ReferenceCode>
<EligibleCard xsi:type="xsd:string"/>
<Errorcode xsi:type="xsd:int">6</Errorcode>
<Errorinfo xsi:type="xsd:string">Duplicate application</Errorinfo>
<RequestIP xsi:type="xsd:string">xx.xx.xx.xx</RequestIP>
</return></ns1:creditCardResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
尝试了很多事情,这是我提出请求的最终代码。
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:creditCard">
<SOAP-ENV:Body>
<ns1:creditCardResponse xmlns:ns1="urn:creditCard">
<return xsi:type="tns:RPResponse">
<Status xsi:type="xsd:int">1</Status>
<ReferenceCode xsi:type="xsd:string">#xxxxxx</ReferenceCode>
<CreditLimit xsi:type="xsd:string">75000</CreditLimit>
<NTCFlag xsi:type="xsd:string"/>
<DecisionSegment xsi:type="xsd:string"/>
<EligibleCard xsi:type="xsd:string">0</EligibleCard>
<ResParam1 xsi:type="xsd:string">http://xxx-xx.xxxxxx.xxx/xxx-xx-xxx?CustomerToken=xxx&E=xxx</ResParam1>
<Errorcode xsi:type="xsd:int">0</Errorcode>
<Errorinfo xsi:type="xsd:string"/>
<RequestIP xsi:type="xsd:string">xx.xx.xx.xx</RequestIP>
<MobileMatchFlag xsi:type="xsd:string">Y</MobileMatchFlag>
</return>
</ns1:creditCardResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>