【问题标题】:ReactNative - axios - http request to get xml feedReactNative - axios - 获取 xml 提要的 http 请求
【发布时间】:2018-03-01 16:54:55
【问题描述】:

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 提要?

这是我得到的错误:

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

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

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

async (default false): 回调应该是异步的吗?这可能是一个 如果您的代码依赖于同步执行 回调。 xml2js 的未来版本可能会更改此默认值,因此 建议无论如何都不要依赖同步执行。添加于 0.2.6.

【问题讨论】:

    标签: xml reactjs react-native axios


    【解决方案1】:

    这应该可以工作

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

    不知道具体,但我想试试看。

    【讨论】:

      【解决方案2】:

      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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-09
        • 1970-01-01
        • 2021-09-12
        • 1970-01-01
        • 2018-12-26
        • 2020-08-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多