0
Good morning guys, I’m stuck since yesterday and need help. I can’t connect the app I’m developing the api that is on my pc.
1° Error 404
2° I don’t know if I’m making the request the right way ( My device is on the same computer network and I was able to access the API by it - this indicates that they are communicating, the problem must actually have the code I’m writing ")
3° Please, I need a hint on how to use this with Async Storage
Code made for the request:
constructor(props) {
super(props);
state = {
email: '',
password: '',
error: '',
sucesso: false
};
this.loginUser = this.loginUser.bind(this);
}
loginUser() {
const { email, senha } = this.state;
this.setState({ error: '', sucesso: true});
axios.post('http://localhost/api/login',{
user: {
email: email,
senha: senha
}
},)
.then((response) => {
alert(response);
})
.catch((error) => {
alert(error);
});
}
Below the form code:
<View style={styles.inputContainer}>
<Text style={styles.textLabel}>E-mail</Text>
<TextInput
style={styles.input}
onChange={(email) => this.setState( user.email )}
/>
<Text style={[styles.textLabel, style = { marginTop: '5%' }]}>Senha</Text>
<TextInput
style={styles.input}
secureTextEntry={true}
onChange={(newValue) => this.setState( user.senha )}
/>
<Ripple style={styles.forgottenPw} onPress={() => this.props.navigation.navigate('PasswordRecovery')}>
<Text>
Esqueceu a sua senha?
</Text>
</Ripple>
<Button style={styles.btnAcess}
onPress={() => this.loginUser()}>
<Text style={styles.textBtnAcess}>ENTRAR</Text>
</Button>
</View>
When I put the localhost ip in my smartphone browser I can see the folders and access the dasbhoard by it in the same way as access by pc ( Both are on the same network )
– Paulo Freire
has already tested the post for the address
http://localhost/api/login
with thepostman
or similar?– Neuber Oliveira
Yeah, and it worked!
– Paulo Freire
I decided, Thank you. :)
– Paulo Freire
Tell me how you resolved it please
– Neuber Oliveira
I used the absolute path to where the api is. Instead of "http://ip/api/login/". I put "http://ip/folder_do_project/public/api/login".
– Paulo Freire