简体   繁体   English

Axios 并且 Fetch 不适用于我的 android 的 React Native 应用程序

[英]Axios and Fetch is not working for my react Native app for android

I am always getting Network error alert for the below API axios get request.我总是收到以下 API axios 获取请求的网络错误警报。 Please suggest what is wrong with my url given.请建议我给出的 url 有什么问题。 I read so many posts and i think my url is not correct.我读了很多帖子,我认为我的 url 不正确。 I have added my ip with port number in between of https:// and api. Kindly help what needs to be updated in the code.我添加了我的 ip,端口号介于 https:// 和 api 之间。请帮助代码中需要更新的内容。 React Native-Axios-Android Emulator React Native-Axios-Android 模拟器

import React from 'react';
import { View, Text, Button } from 'react-native';
import axios from 'axios';


function WelcomePage({ navigation }) {

const dataFetch = async () => {

    try {
        const response = await axios.get('https://192.168.1.4:5554/reactnative.dev/movies.json');
        alert(JSON.stringify(response.data));
    }
    catch (error) {
        alert(error.message);
    };
}


return (
    <View>
        <Text>Welcome!</Text>
        <View>
            <Button
                title="Fetch Name and DOB"
                onPress={dataFetch}></Button>
            <Text></Text>
            <Button
                title="Go to Profile Page"
                onPress={() => navigation.navigate("Cart")}></Button>
        </View>
    </View>
);
  }
  export default WelcomePage;

You are using https://192.168.1.4:5554/reactnative.dev/movies.json , but localhost doesn't support https, change to http://192.168.1.4:5554/reactnative.dev/movies.json it should work.您正在使用https://192.168.1.4:5554/reactnative.dev/movies.json ,但 localhost 不支持 https,更改为http://192.168.1.4:5554/reactnative.dev/movies.json工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM