简体   繁体   English

在带有React Native 0.44的IOS模拟器中无法进行抓取

[英]fetch is not work in IOS simulator with React Native 0.44

Fetch is not working in IOS simulator with React Native 0.44. 使用React Native 0.44的IOS模拟器中,抓取无法正常工作。 I'm trying to create a login form in react native using fetch. 我正在尝试使用访存本机创建登录表单。

This is my code, 这是我的代码

login.ios.js

import React, { Component } from 'react';
import { StyleSheet,TextInput,ActivityIndicatorIOS,TouchableHighlight, Text, View } from 'react-native';

class Login extends Component {
  constructor(){
    super();
    this.state = {
      reg_mob_no: "",
      password: "",
      error: "",
      showProgress: false,
    }
  }


  async onLoginPressed() {
    this.setState({showProgress: true})
    try {
      let response = await fetch('http://example.in/api/premiumuser/login', {
                              method: 'POST',
                              headers: {
                                'Accept': 'application/json',
                                'Content-Type': 'application/json',
                              },
                              body: JSON.stringify({
                                  reg_mob_no: this.state.reg_mob_no,
                                  password: this.state.password,
                              })
                            });
      let res = await response.text();
      console.log("res is:" + res );
    } catch(error) {
    }
  }
  render() {

    return (
      <View style={styles.container}>
        <Text style={styles.heading}>
              Login Form!
            </Text>
        <TextInput
          onChangeText={ (text)=> this.setState({reg_mob_no: text}) }
          style={styles.input} placeholder="Registered Mobile No">
        </TextInput>
        <TextInput
          onChangeText={ (text)=> this.setState({password: text}) }
          style={styles.input}
          placeholder="Password"
          secureTextEntry={true}>
        </TextInput>
        <TouchableHighlight onPress={this.onLoginPressed.bind(this)} style={styles.button}>
          <Text style={styles.buttonText}>
            Login
          </Text>
        </TouchableHighlight>

        <Text style={styles.error}>
          {this.state.error}
        </Text>


      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'flex-start',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
    padding: 10,
    paddingTop: 80
  },
  input: {
    height: 50,
    marginTop: 10,
    padding: 4,
    fontSize: 18,
    borderWidth: 1,
    borderColor: '#48bbec'
  },
  button: {
    height: 50,
    backgroundColor: '#48BBEC',
    alignSelf: 'stretch',
    marginTop: 10,
    justifyContent: 'center'
  },
  buttonText: {
    fontSize: 22,
    color: '#FFF',
    alignSelf: 'center'
  },
  heading: {
    fontSize: 30,
  },
  error: {
    color: 'red',
    paddingTop: 10
  },
  success: {
    color: 'green',
    paddingTop: 10
  },
  loader: {
    marginTop: 20
  }
});


module.exports = Login;

I am not getting any response from server when clicked on registerbutton. 单击注册按钮时,服务器没有任何响应。

This same source in working with expo but not working in ios simulator. 与expo一起使用的相同来源,但在ios模拟器中不使用。 Developer tool showing nothing. 开发人员工具什么也没显示。

How to solve this issue.. Please help!!! 如何解决这个问题..请帮忙!!!

React Native version: 0.44 Platform: IOS Development Operating System: mac os 10.12 Build tools: Xcode 9 React Native版本:0.44平台:IOS开发操作系统:mac os 10.12构建工具:Xcode 9

Try to include the key-value pair credentials: 'include' in fetch options. 尝试在获取选项中credentials: 'include'键值对credentials: 'include' RN 0.44 introduced withCredentials XHR flag, as you can see here . RN 0.44引入了带有凭据XHR标志,如此处所示

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

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