【问题标题】:Error 415 on POST image to WEBAPI with Axios使用 Axios 将图像 POST 到 WEBAPI 时出现错误 415
【发布时间】:2020-10-08 19:44:55
【问题描述】:

我正在尝试使用 axios 向我服务器上的 WebApi 发送一个 Post 请求,使用 PostMan 测试 API,API 接受并正常工作。

但在我的 React Native App 上,当我发送 axios.post 时,它返回“错误:请求失败,状态码 415”。 当我用 postData Returns Error:Network Error 发送帖子时,什么时候 我按照下面的方式发送它返回Error 415。

我进行了很多搜索,但无法解决这个问题。有人可以帮忙吗? 贝娄是我的 js 代码。

let postData = new FormData();
                          postData.append('file',{ uri: response.uri });
                          postData.append('auditid',auditID);
                          //axios.post("http://172.16.0.10:8081/api/auditpicture/", postData,{

                          axios.post("http://172.16.0.10:8081/api/auditpicture/",{
                            headers: {
                              "Content-Type": 'multipart/form-data; boundary=${formData._boundary}',
                             }
                              ,
                              body:
                               [{
                                 file:response.uri,
                                 auditid:auditID
                               }]
                          }).then(response=> {
                            console.log(response.data)
                          }).catch(error=>{
                            console.log(error);

                          })

这是 PostMan 的返回:

【问题讨论】:

    标签: reactjs react-native post axios


    【解决方案1】:

    很久以后我会发布这个问题的答案。在发现其他人也有同样的问题后,我放弃了使用 axios 发布图像,而是使用了 RNFetchBlob.fetch 库,它很容易工作。

    【讨论】:

      猜你喜欢
      • 2017-01-07
      • 2017-05-03
      • 1970-01-01
      • 2018-07-30
      • 2021-06-29
      • 2020-11-04
      • 1970-01-01
      • 2018-04-01
      • 1970-01-01
      相关资源
      最近更新 更多