最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "multipart != applicationjson" fetch post error on android (react-native) - Stack Overflow

programmeradmin3浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 22

you have to change the 'Content-Type' to

'Content-Type': 'multipart/form-data'
发布评论

评论列表(0)

  1. 暂无评论