繁体   English   中英

ReactNative-axios-获取XML提要的HTTP请求

[英]ReactNative - axios - http request to get xml feed

JSON响应按预期工作

axios.get('https://rallycoding.herokuapp.com/api/music_albums')
      .then(response => console.log(response))

无法获得响应可能是因为它是XML?

axios.get('http://thefederalistpapers.org/feed')
      .then(response => console.log(response))

axios是否可以获取XML feed?

这是我得到的错误:

可能的未处理的承诺拒绝(标识:0):
错误:网络错误

基本上我想做的是从HTTP请求中获取XML,但我不确定如何将其转换为JSON

我什至尝试了这个react-native-xml2js,但是没有帮助,因为它不支持异步(不确定)。

异步(默认为false):回调应该异步吗? 如果您的代码取决于回调的同步执行,则这可能是不兼容的更改。 将来的xml2js版本可能会更改此默认设置,因此建议无论如何不要依赖于同步执行。 在0.2.6中添加。

ios-app-transport-security-and-loading-http-resources

这是React Native iOS中的一个已知问题,除非您在info.plist中做了例外,否则它不允许HTTP协议仅使用https

https://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9/30732693#30732693

这应该工作

axios.get('linkgoeshere', { headers: { 'Accept': 'application/json' }})
  .then(response => console.log(response));

不知道确切,但我想尝试一下。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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