网络请求失败-Expo React Native



这真的很烦人。如果我使用http://my-domain.com其处理out网络请求失败,但是https://my-domain.com它不断给我网络请求失败的错误。

我一直在网上查找,但仍然没有解决这个问题。请帮忙。

package.json

"dependencies": {
"@expo/vector-icons": "~10.0.6",
"@react-native-community/masked-view": "0.1.6",
"@react-navigation/bottom-tabs": "^5.0.0",
"@react-navigation/native": "^5.0.0",
"@react-navigation/stack": "^5.0.0",
"@react-navigation/web": "~1.0.0-alpha.9",
"expo": "~37.0.3",
"expo-asset": "~8.1.3",
"expo-constants": "~9.0.0",
"expo-font": "~8.1.0",
"expo-web-browser": "~8.1.0",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-gesture-handler": "~1.6.0",
"react-native-iphone-x-helper": "^1.2.1",
"react-native-modalize": "^1.3.7-rc.19",
"react-native-safe-area-context": "0.7.3",
"react-native-screens": "~2.2.0",
"react-native-web": "~0.11.7"

},

获取代码

const [contents, setContents] = useState([]);
const fetchChannelContent = (slug) => {
fetch(Http.api+"/channel/"+slug)
.then((response) => response.json())
.then((json) => {
setContents(json.channel.content);
})
.catch((error) => {
console.error(error);
});
};
useEffect(() => {
fetchChannelContent(url)
}, []);[![enter image description here][1]][1]

[1] :

Http类

export default {
api: "https://my-domain.com"

}

export default url {
api: "https://my-domain.com"
}

然后导入该文件和用户url.api

最新更新