Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"multipart != application/json" fetch post error on android (react-native)

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);
        });

enter image description here

like image 529
Emre Tekince Avatar asked Sep 06 '16 14:09

Emre Tekince


1 Answers

you have to change the 'Content-Type' to

'Content-Type': 'multipart/form-data'
like image 54
Abdulaziz Alkharashi Avatar answered Nov 16 '22 21:11

Abdulaziz Alkharashi