首页 文章

React Native - 使用身份验证获取

提问于
浏览
-1

我目前在React Native中开发一个应用程序,使用Python中的API . 我想获取一个需要身份验证的页面:

My authentication page

我正在使用POST方法获取:

export default class WebaurionScreen extends Component {
  constructor(props){
    super(props);
    this.state ={ isLoading: true}
  }

  state = {
      'login': '',
      'pwd': ''
   }

   componentDidMount = () => {

        AsyncStorage.getItem('login').then((value) => this.setState({ 'login': value }))
        AsyncStorage.getItem('pwd').then((value) => this.setState({ 'pwd': value }))

        return fetch('https://api-five.herokuapp.com/webaurion/login_aurion',{
        method: 'POST',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            login: 'mylogin',
            psw: 'mypassword',
        })
        })

        .then((response) => response.json())
        .then((responseJson) => {
            this.setState({
                isLoading: false,
                dataSource: responseJson.NOTES,
            });
        })
        .catch((error) =>{
        console.error(error);
      });
    }

但它根本不起作用......

你能帮我解决这个问题吗?

1 回答

  • 0

    我正在玩这个有一段时间,但后来只是https://github.com/axios/axios它应该工作,有一个本地扩展,但它不是必需的 .

相关问题