android - React-Native“网络请求失败”与Android上的表单数据
问题描述
我目前正在尝试使用 React-Native 应用程序中的表单数据发送图像和数据。它实际上在真正的 iOs 设备上运行良好,但在真正的 Android 设备上却不行。
我的 Android 设备console.log(error)
从.catch
.
这是代码:
export(user, base64) {
var formData = new FormData();
formData.append("user", JSON.stringify(user));
for (var key in base64) {
formData.append("image" + [key], {
uri: "data:image/png;base64," + base64[key],
type: "image/png",
name: "image" + [key]
});
}
return new Promise((fulfill, reject) => {
fetch("https://url.fr", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "multipart/form-data",
userkey: userkey
},
body: formData
})
.then(response => {
if (response.ok) {
return response.json();
} else {
console.log(response);
return {
success: false
};
}
})
.then(responseJson => {
fulfill(responseJson);
})
.catch(error => {
console.log(error)
// alert(error);
reject(error);
});
});
}
如果您知道我的代码出了什么问题,请随时帮助我;)
谢谢。
解决方案
推荐阅读
- python - 如何访问模型类定义中的 Django 模型属性?
- python - 组合头文件数组中的非零元素
- r - 如何使用 geom_point() 更改点的线宽?
- javascript - 错误:不是功能(已安装)
- javascript - 通过 Mongoose 回调传递值
- javascript - 在输入组插件类下添加文本
- cookies - 使用 Jhipster 的网关和不带 cookie 的 UAA 进行 Oauth2 身份验证
- ios - 你如何在 Objective C 中播放背景音乐?
- ios - 如何从 Xcode 运行在 iPhone 上持久化应用程序?
- python - 选择具有所需数据类型的熊猫系列并就地应用功能的方法