【问题标题】:React native rn-fetch-blob download with post method使用 post 方法反应本机 rn-fetch-blob 下载
【发布时间】:2021-08-11 13:41:34
【问题描述】:

我需要通过代码下载来自flask rest API的文件(.pdf)

return send_file(file_location, as_attachment=True)

我尝试使用 RNFetchBlob

RNFetchBlob
        .config({
            addAndroidDownloads: {
                useDownloadManager: true, // <-- this is the only thing required
                // Optional, override notification setting (default to true)
                notification: false,
                // Optional, but recommended since android DownloadManager will fail when
                // the url does not contains a file extension, by default the mime type will be text/plain
                mime: 'application/pdf',
                description: 'File downloaded by download manager.',
            },
          })
          .fetch('POST', 'http://192.168.0.199:8000/v1/quote/view', data)
          .then((res)=>console.log('The file saved to ', res.path()))
          .catch((err)=>console.log(err));

但即使我在烧瓶中提到 POST 方法,它也会作为 GET 方法接收

192.168.0.186 - - [11/Aug/2021 19:05:31] "GET /v1/quote/view HTTP/1.1" 405 -

我做错了什么?

【问题讨论】:

  • 您可能在 fetch 中缺少标题作为第三个参数。
  • 我正在添加我希望作为第三个参数发送的数据,
  • 刚刚在问题中更新了

标签: react-native rn-fetch-blob


【解决方案1】:

感谢@Xhirazi,

顺序应该是这样的 fetch(Method, URL, headers, body),修复了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 2022-07-08
    • 1970-01-01
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    • 2020-01-20
    相关资源
    最近更新 更多