React Native - Fetch POST request is sending as GET request

后端 未结 11 1150
感情败类
感情败类 2020-12-16 14:52

I\'m having issues when using FETCH.

I am trying to make a POST request using FETCH in react-native.

    fetch(\"http://www.example.co.uk/login\", {
         


        
11条回答
  •  没有蜡笔的小新
    2020-12-16 15:47

    Use FormData. Problem is with JSON.stringify. You can directly import, its not third party

    import FormData from 'FormData';
    ...
    var data = new FormData();
    data.append("username", "ABCD");
    data.append("password", "1234");
    fetch('YOUR_URL', {
    method: 'POST',
    headers: {
        Accept: 'application/json',
        'Content-Type': 'multipart/form-data',
    },
    body:data,
    })
    .then((response) => response.json())
    .then((responseJson) => {
        console.log('response object:',responseJson)
    })
    .catch((error) => {
      console.error(error);
    });
    

提交回复
热议问题