0

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 '<'

POSTMAN TESTER AND RESPONSE JSON

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?

1
  • 1
    I haven't looked at your code, but this error often suggests that the server responded with XML (or HTML) instead of json. Commented Apr 15, 2020 at 9:59

1 Answer 1

0

Please check your headers in code is matching with the postman or not..

Sign up to request clarification or add additional context in comments.

1 Comment

see 13 parameters from where?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.