简体   繁体   English

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

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

The JSON response works as expected JSON响应按预期工作

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

Not able to get response may be because it's XML? 无法获得响应可能是因为它是XML?

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

Does axios work to fetch XML feed? axios是否可以获取XML feed?

Here is the error I am getting: 这是我得到的错误:

Possible Unhandled Promise Rejection (id: 0): 可能的未处理的承诺拒绝(标识:0):
Error: Network Error 错误:网络错误

Basically what I am trying to do is, get the XML from HTTP request and I am not sure how to convert it to JSON 基本上我想做的是从HTTP请求中获取XML,但我不确定如何将其转换为JSON

I even tried this react-native-xml2js but did not help because it doesn't support async, not sure. 我什至尝试了这个react-native-xml2js,但是没有帮助,因为它不支持异步(不确定)。

async (default false): Should the callbacks be async? 异步(默认为false):回调应该异步吗? This might be an incompatible change if your code depends on sync execution of callbacks. 如果您的代码取决于回调的同步执行,则这可能是不兼容的更改。 Future versions of xml2js might change this default, so the recommendation is to not depend on sync execution anyway. 将来的xml2js版本可能会更改此默认设置,因此建议无论如何不要依赖于同步执行。 Added in 0.2.6. 在0.2.6中添加。

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

this is known issue in react native iOS it dose not allow http protocol only https unless you made an exception in info.plist 这是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 https://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9/30732693#30732693

This should work 这应该工作

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

Dont know exactly but try it I guess. 不知道确切,但我想尝试一下。

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

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