Javascript 响应本机can';拿不到
当我在React Native(0.20.0)中获取以下url时: 获取代码:Javascript 响应本机can';拿不到,javascript,android,reactjs,react-native,Javascript,Android,Reactjs,React Native,当我在React Native(0.20.0)中获取以下url时: 获取代码: API.prototype.GET = function(url, callback) { console.log('GET>>:' + url); return fetch(url) .then(parseJSON) .then((responseData) => { if (responseData != null) { if (responseDat
API.prototype.GET = function(url, callback) {
console.log('GET>>:' + url);
return fetch(url)
.then(parseJSON)
.then((responseData) => {
if (responseData != null) {
if (responseData.code != 200) {
RNManager.showMessage(responseData.message);
return;
}
}
return callback(responseData);
})
.catch((error) => {
console.warn(error);
})
.done();
}
报告说:
(标准输入):145715:W/ReactNativeJS(13624):[TypeError:网络请求失败]
但是这个Url可以在chrome中加载。我认为是490 | 1491 | 1485 | 1的格式导致了这个问题。但如何解决这个问题呢
[已解决]问题是fetch()没有为我执行URL\u编码,所以我自己将“|”更改为“%7C”(URL\u编码),它成功了
[Solved Update]使用encodeURI()
完成这些技巧
API.prototype.GET = function(url, callback) {
console.log('GET>>:' + url);
return fetch(url)
.then(parseJSON)
.then((responseData) => {
if (responseData != null) {
if (responseData.code != 200) {
RNManager.showMessage(responseData.message);
return;
}
}
return callback(responseData);
})
.catch((error) => {
console.warn(error);
})
.done();
}