I have an app which is builded with react-native and it's running perfectly in iOS.
I am making it also available for Android but there is a error when trying to post contact form data to my server.
var formData = new FormData()
formData.append('name', fullname)
formData.append('email', email)
formData.append('message', message + ' -- Sent from Android app')
fetch('', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: formData
}).then((response) => response.json())
.then((data) => {
if (data.success
...
else
...
})
.catch((error) => {
console.warn(error);
});
I have an app which is builded with react-native and it's running perfectly in iOS.
I am making it also available for Android but there is a error when trying to post contact form data to my server.
var formData = new FormData()
formData.append('name', fullname)
formData.append('email', email)
formData.append('message', message + ' -- Sent from Android app')
fetch('https://www.xxxx.com/mail', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: formData
}).then((response) => response.json())
.then((data) => {
if (data.success
...
else
...
})
.catch((error) => {
console.warn(error);
});
Share
Improve this question
asked Sep 6, 2016 at 14:03
Emre TekinceEmre Tekince
1,8435 gold badges20 silver badges31 bronze badges
1 Answer
Reset to default 22you have to change the 'Content-Type' to
'Content-Type': 'multipart/form-data'