Retrofit进行WebService请求遇到的问题总结

前面写了一篇利用Retrofit进行WebService请求的文章,地址是:http://blog.csdn.net/smileiam/article/details/51957232,下面说说自己在调试过程中,遇到的一些问题及解决办法。给其他遇到类似问题的小伙伴,一些参考。


1. soapaction header missing,no SOAPAction header

这个一般是请求的方法,请求头中没有添加SOAPAction,只需要在写请求方法的头上添加上相应的Action

@Headers({"Content-Type: text/xml;charset=UTF-8", "SOAPAction: http://WebXml.com.cn/getWeatherbyCityName"})//请求的Action

2. soapenv:VersionMismatch
这个在stackoverflow上有人给出解释:The faulting node found an invalid element information item instead of the expected Envelope element information item. The namespace, local name or both did not match the Envelope element information item required by this recommendation
大意是因为命名空间写的不对,或是结点元素无效,不是期望的Envelope元素等。
像我是因为粗心,命名空间忘记写最后面的反斜杠。下面是错误的写法:
@Namespace(reference = "http://schemas.xmlsoap.org/soap/envelope", prefix = "env")
正确的写法应该是:
@Namespace(reference = "http://schemas.xmlsoap.org/soap/encoding/", prefix = "enc"),
所以说程序员一定要细心。
3. <faultcode>soapenv:Server.userException</faultcode>
<faultstring>org.xml.sax.SAXParseException: The prefix soapenv for element soapenv:Envelope is not bound.</faultstring>
从报错的原因里,可以看出是因为在命名空间里,没有定义前缀为soapenv这个的空间
这主要是我写命名空间
@Namespace(reference = "http://schemas.xmlsoap.org/soap/envelope/", prefix = "soapenv")的前缀明明写的是soapenv,可是在代码中却用成类似
@Element(name = "env:Body", required = false)
Body前面的前缀应该和prefix里的对应上
4. org.simpleframework.xml.core.ElementException: Element 'Body' does not have a match in class com.combanc.common.communication.webservice.ResponseEnvelope at line 1
这一般是在对Retrofit返回的数据,解析xml时报的错,写的Body的model对应错了
注意Retrofit里的XML解析,用的是SAX解析,每一个标签都应该解析到,要不会报错。属性也需要进行解析的。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值