首页 > 解决方案 > 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);
       });
   });
}

如果您知道我的代码出了什么问题,请随时帮助我;)

谢谢。

标签: androidreact-nativeform-data

解决方案


推荐阅读