我正在尝试将文件从我的 Node js 应用程序发送到托管 opencart 应用程序的 PHP 服务器。 我正在使用 formdata 和 axios 模块来发出请求并上传文件。
我的问题是我收到此错误 错误:请求失败,状态代码 503
如何解决?
这是我在 Node.js 中的代码:
let form = new FormData();
form.append("file", fs.createReadStream(path.resolve(zipFilePath)), path.basename(zipFilePath));
try {
let response = await axios.post(endpoint, form, {
headers: {
...form.getHeaders(),
},
});
const result = response.data;
if (result && result.status === "success") {
fs.unlinkSync(zipFilePath);
}
} catch (e) {
console.log(e.toString());
}
和 php 代码(控制器中的函数):
public function upload() {
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
$this->response->setOutput(json_encode([]));
} else {
// process the file posted
}
} Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
问题已解决。
问题是opencart应用程序在后端设置为维护模式,但前端仍然正常工作,所以之前没有注意到。