【发布时间】:2017-12-27 07:20:27
【问题描述】:
我在前端使用 React-native,在我的服务器上使用 PHP 后端。我需要能够将密码发送到要从中下载文件的服务器。如果密码正确,我正在连接到使用 X-SendFile 库将文件发回的 PHP 脚本。
目前我正在使用 RNFS.downloadFile() 下载和保存文件,但这似乎只适用于 GET 而不适用于 POST。我希望能够将文件保存到 DocumentDirectoryPath。
我当前的代码如下所示:
await RNFS.downloadFile({
fromUrl: 'http://example.com/myfile.zip',
toFile: RNFS.DocumentDirectoryPath + "/userdata/myfile.zip",
}).promise
我希望能够做这样的事情:
await RNFS.downloadFile({
method: post,
body: {passcode: "abc123", filename: "myfile.zip"},
fromUrl: 'http://example.com/getfile.php',
toFile: RNFS.DocumentDirectoryPath + "/userdata/myfile.zip",
}).promise
如何更改我的代码以将密码作为 POST 参数传递?
【问题讨论】:
-
参考使用文档github.com/itinance/react-native-fs - 这是 RNFS.uploadFiles({ method:post.... 不是 RNFS.downloadFile({ method: post ... 用于上传文件。
标签: post react-native x-sendfile