【问题标题】:React Native, getting network error while posting FormData with AxiosReact Native,在使用 Axios 发布 FormData 时出现网络错误
【发布时间】:2020-09-07 07:33:01
【问题描述】:

我正在尝试通过创建 FormData 来发送音频/图像。

我当前的版本是:“react-native”:“0.59.10”,“axios”:“^0.19.2”,“react”:“16.8.3”。我正在我的安卓设备上测试我的应用程序

在发送 FormData 时每次都会出现“网络错误”。

这是我创建和发送帖子的方式;

  let new_options = {
    headers: {
      'Content-Type': 'multipart/form-data',
      'Authorization': myAuthorization
    }
  };
  const content = new FormData();
  content.append('file', {
    uri: 'file://' + attachment.path,
    name: 'test',
    type:  attachment.type
  });
  content.append('ReportId', report_id);
  content.append('MimeType', attachment.type);
  
  try {
    let res = await axios.post(myUrl, content, new_options);
  }catch(err){
    console.warn(err);
  }

我已经尝试过更新 FLIPPER_VERSION 或编辑 ReactNativeFlipper.java,但我的项目中不存在这些东西,因为我使用的是旧版本的 react-native。我也试过删除调试文件夹。

【问题讨论】:

    标签: react-native axios react-native-android


    【解决方案1】:

    想通了,问题是由错误的 MimeTypes 引起的。

    【讨论】:

      猜你喜欢
      • 2019-10-30
      • 2020-04-23
      • 2021-07-07
      • 2022-09-30
      • 1970-01-01
      • 2017-12-29
      • 2020-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多