我正在使用 React Native 来开发 Android 应用程序。通过此获取请求,我收到错误TypeError: network request failed
:
fetch('https://pixabay.com/api/?key=MY_KEY&q='+ this.props.jsondata.city.name +'&lang=en&image_type=photo&orientation=horizontal&category=travel&safesearch=true')
.then(response => {
console.dir(response);
if (!response.ok) {
throw Error(data.statusText);
}
return response.json();
})
.then(json => {
console.log(json.hits[0].largeImageURL)
this.setState(() => {
return {backImage: json.hits[0].largeImageURL};
});
})
.catch(err => {
console.log('Unable to search image! ' + err);
});
我已经在网上搜索过,但这个问题仅出现在本地主机地址或http上,这不是我的情况。请求位于componentDidMount()
功能。我在应用程序的另一个地方提出了类似的请求(具有相同的结构),但那里没有错误。我正在使用真正的 Android 设备来测试应用程序以及在 Android 本机代码中编译的 React-Native 应用程序。
Add android:usesCleartextTraffic="true"
in AndroidManifest.xml
.
从 android 文件夹中删除所有 debug 文件夹。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)