簡體   English   中英

表示不推薦使用的 res.send(status, body):即使表達式更改,使用 res.status(status).send(body) 也不起作用

[英]express deprecated res.send(status, body): Use res.status(status).send(body) does not work even when expresion change

我正在嘗試在我的 POST 中為我的 Express 應用返回一個 JSON。

我收到了錯誤“express deprecated res.send(status, body): Use res.status(status).send(body)”但即使我更改了帶有錯誤的行,它仍然顯示相同的錯誤。

我的 package.json 是:

{
  "name": "Email",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@azure/cognitiveservices-face": "^4.2.0",
    "@azure/ms-rest-js": "^2.6.0",
    "axios": "^0.23.0",
    "express": "^4.17.1",
    "nodemailer": "^6.7.0"
  }
}

我用於快遞的名稱:

const express = require("express");
const bodyParser = require("body-parser");

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

我試圖獲得成功響應的代碼是:

app.post("/analisis/faceid", (req, res) => {
  let img = req.body.img;

  axios({
    method: "post",
    url: endpoint_faceID,
    params: {
      detectionModel: "detection_03",
      returnFaceId: true,
    },
    data: {
      url: img,
    },
    headers: {
      "Ocp-Apim-Subscription-Key": Ocp_Apim_Subscription_Key,
    },
  })
    .then(function (response) {
      let response_data = {
          mgs: "OK",
        faceId: response.data[0].faceId
      };
      res.send(response_data); //HERE IS WHERE THE ERROR APPEARS 
    })
    .catch(function (error) {
      res.send("ERROR AT FACE ID : ", error);
    });
});

我嘗試將其替換為:

res.json(response_data)
res.jsonp(200, response_data)
res.status(200).send(response_data)
res.status(200).send(JSON.stringify(response_data))
res.status(200).json(response_data)
res.status(200).jsonp(response_data)

但我不斷收到同樣的錯誤。

PD:對不起我的英語

謝謝大家。

問題是我試圖傳遞捕獲的 2 個參數

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM