我正在嘗試將文件從我的 Node js 應(yīng)用程序發(fā)送到托管 opencart 應(yīng)用程序的 PHP 服務(wù)器。 我正在使用 formdata 和 axios 模塊來(lái)發(fā)出請(qǐng)求并上傳文件。
我的問(wèn)題是我收到此錯(cuò)誤 錯(cuò)誤:請(qǐng)求失敗,狀態(tài)代碼 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 代碼(控制器中的函數(shù)):
public function upload() { header('Access-Control-Allow-Origin: *'); if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { $this->response->setOutput(json_encode([])); } else { // process the file posted } }
問(wèn)題已解決。
問(wèn)題是opencart應(yīng)用程序在后端設(shè)置為維護(hù)模式,但前端仍然正常工作,所以之前沒(méi)有注意到。