简体   繁体   中英

Retrofit: Loading xml feed from url returns scrambled response body

I have an issue with load XML feed from url using Retrofit.

Given a dynamic url that clearly returns xml feed fe: https://anchor.fm/s/53faae8/podcast/rss

When I try to load this via Retrofit I can see in Android Studio Network Profilier that it returns a scrambled response. Something like this:

ì½ÝvÜF’.z=ó­5mÏ&d&€ÛmÊ’Ûš¶-K=š>{íµWH°`Ve EšsÕ÷çö¬5ûö
<X?ɉˆLüT‰jIUîÖL·šUäoDFdü|ñÙ?¯–Þ•iÚ²®~÷$8õŸx¦Ê꼬.~÷ä�o¾bêÉŸÖ´­VíYžýîÉ¢ëÖgOŸ®7Íò´n.žæÙS³4+SuíÓà4xúÄ=›ÕU_¾û4úOWu¾Yšö©{pxQwõjxëúúúôZÐ{Ü÷ççðã“qȇl_+»MeÚ­

Etc.

I've added an xml converter in my retrofitBuilder:

retrofitBuilder.addConverterFactory(SimpleXmlConverterFactory.createNonStrict(Persister(AnnotationStrategy())))

And my service code to retrieve the xml from url looks like: interface XmlFeedService {

@GET 
fun getXmlFeedFromUrl(@Url url: String): Call<RssFeed>

I am using @Url annotation here since the url is dynamic and depending what another api returns to me can result in urls with different base url's.

Of course the response body can't be parsed like this, but I am unclear why it comes back like this. Can anyone help out?

Figured it out already.It's not due to a wrong configuration of the Retrofit builder or the service, but the scrambled response that the Network Profiler showed me was due to the some of the Annotation in the Data models being wrongly configured...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM