React-Native获取XML困难

时间:2018-09-24 14:43:33

标签: react-native fetch

我试图用react-native从XML捕获数据两天。 我当前的代码:

const parseString = require('react-native-xml2js').parseString;

fetch('https://sandbox.lojamestre.com.br/api.asp?mensagem=<?xml version="1.0" encoding="ISO-8859-1"?><requisicao-transacao><Authentication><Token>wabqzh3XXXx2ytdwmgu7b2</Token><Comando>VR</Comando></Authentication><Records><Record><DateStart>01/11/2017</DateStart><DateEnd>01/11/2017</DateEnd></Record></Records></requisicao-transacao>')
    .then((response) => response.text())
    .then((responseText) => {
        parseString(responseText, function (err, result) {
            console.log(responseText)
        });
    })
    .catch((err) => {
        console.log('Error fetching the feed: ', err)
})`</code></pre>

我尝试了几种代码变体,但是无法捕获从fetch返回的XML。 它给了我未定义的错误或什么都不返回。

有人可以帮我吗? 在上面的这段代码中,我应该返回。

xml version=1.0 encoding=ISO-8859-1
requisicao-transacao
Erro
code Var_Tokcode
motivo Token Inválid omotivo
/Erro
/requisicao-transacao

0 个答案:

没有答案