I'm learning react native. here I am making a login logout API to use clien. when i try in postman, the result is right and right but when I use the API, I get a problem which is:
JSON Parse error: Unrecognized token '<'
this my code
class AuthScene extends Component {
constructor(props) {
super(props);
this.state = {
username : '',
password : ''
}
}
login= ()=>{
const {username,password} = this.state;
// alert(username);
fetch('https://example.com/auth', {
method: 'POST',
headers: {
'Accept' : 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: username,
password: password
})
})
.then((response) => response.json()).then((responseJson) => {
alert(JSON.stringify(responseJson));
console.log(JSON.stringify(responseJson, null, 4))
}).catch((error) => {
alert(JSON.stringify(error));
console.log(error);
// done();
});
}
and
render() {
return (
<Form style={styles.mainForm}>
<Item style={styles.formItems}>
<Input placeholder="Username" style={styles.Input} onChangeText={username => this.setState({username})}/>
</Item>
<Item style={styles.formItems}>
<Input style={styles.Input} secureTextEntry={true} onChangeText={(password) => this.setState({password})}/>
</Item>
<View style={styles.Button}>
<Button block info style={styles.mainBtn} onPress={this.login}>
<Text style={styles.btnText}>Submit</Text>
</Button>
</View>
</Form>
);
}
how to deal with those things?
Is there a problem with my json or my code isn't correct?
