React Native(with expo)fetch with FormData Network error仅在Android上

问题描述 投票:1回答:1

[当我尝试使用fetch和FormData在React Native(expo SDK 37)中使用POST在POST中进行fetch API调用时,一切在IOS上均正常运行,但在Android上出现了网络错误:[TypeError: Network request failed]。如果我使用axios而不是fetch,则会遇到相同的错误(网络错误)。

如果我将formData替换为空{},它将起作用。我已经在模拟器和物理设备(具有各种Android版本)上进行了检查,并且尝试使用标头,但没有结果。我的API有一个公钥,让我们对证书进行加密

let url = 'https://my-prod-server/webservice';

let formData = new FormData();
formData.append('test1','test1');
formData.append('test2','test2');

let request = await fetch(url, {
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'multipart/form-data',
  },
  method: 'POST',
  body: formData,
})
.then(response => response.json())
.catch(error => console.log('API ERROR: ', error));

return request;
android react-native fetch expo form-data
1个回答
0
投票

是否有解决此问题的方法?您如何使用json上传文件?

© www.soinside.com 2019 - 2024. All rights reserved.