React Native Expo iO - 我的Api上的网络请求因Fetch而失败。

问题描述 投票:2回答:1

首先:我看了很多关于这个问题的帖子,测试了所有的帖子,但似乎我被诅咒了,或者类似的东西?

我正在用局域网方法在iOs上做expo.我的后台是在.Net Core 3上,我的iPhone比我的电脑在同一个Wifi上,而我的电脑正在运行我的.Net后台服务器。

我发现localhost不能被exporeact-native处理。所以我尝试了IP adresse方法,并改变了我的后端地址和我的前端地址试图获取。尝试了一些神秘的事情,我不完全理解我的.Net服务器。也试着关闭我的防火墙,它没有改变任何东西.好吧,我不习惯发帖,因为现有的帖子经常回答我的问题。

这是我的代码,关于我的fetch方法。

export async function callPlanning() {
    try {
        let response = await fetch(
          "http://my.Ipv4.adress:myApiPort/myRoute",
        );
        let responseJson = await response.json();
        return responseJson;
      } catch (error) {
        console.error(error);
      }
}

My Api is working well on Postman.And I can call the facebook test api with this function within my app.

这是我的应用代码,我在这里调用这个fetch函数。

export default class BetaserieScreen extends Component {
  constructor(props) {
    super(props)
    this.state={
      response: null,
    };
    this.askPlanning = this.askPlanning.bind(this);
  }

  askPlanning = () => {
    this.setState({
      response: Back.callPlanning(),
    })
  }

  render() {
    return (
      <View style={styles.MainContainer}>
        <Text> Beta Serie </Text>
        <TouchableHighlight onPress={this.askPlanning}>
          <Text>Planning</Text>
        </TouchableHighlight>
      </View>
    );
  }
}

If you see anything that could andwer my question or about my code : I'll take it.I'm on it for 2 days, and I've to find a solution...If you need any other information about my system or file about my project, feel free to ask for it if you think you can help me with this problem.I'll glad.

我会很高兴的。

ios react-native network-programming fetch expo
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.