【问题标题】:"multipart != application/json" fetch post error on android (react-native)“multipart!= application/json”在 android (react-native) 上获取 post 错误
【发布时间】:2016-09-06 14:03:57
【问题描述】:

我有一个使用 react-native 构建的应用程序,它在 iOS 中完美运行。

我正在使它也可用于 Android,但尝试将联系表单数据发布到我的服务器时出现错误。

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

【问题讨论】:

    标签: javascript android react-native


    【解决方案1】:

    您必须将“内容类型”更改为

    'Content-Type': 'multipart/form-data'
    

    【讨论】:

      猜你喜欢
      • 2020-01-28
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 2020-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多