-2

我正在从 ajax 到节点服务器进行后期调用。服务器发出呼叫并给出响应。但在 cmd 提示符下也会显示以下错误

express deprecated res.send(status, body): Use res.status(status).send(body) instead server.js:203:26
_http_server.js:248
throw new ERR_HTTP_INVALID_STATUS_CODE(originalStatusCode);
^RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: exporting started
at ServerResponse.writeHead (_http_server.js:248:11)
at ServerResponse._implicitHeader (_http_server.js:239:8)
at write_ (_http_outgoing.js:650:9)
at ServerResponse.end (_http_outgoing.js:761:5)
at ServerResponse.send (D:\Impex-Node server\node_modules\express\lib\response.js:221:10)
at ServerResponse.json (D:\Impex-Node server\node_modules\express\lib\response.js:267:15)
at ServerResponse.send (D:\Impex-Node server\node_modules\express\lib\response.js:158:21)
at Request._callback (D:\Impex-Node server\server\server.js:203:26)
at Request.self.callback (D:\Impex-Node server\node_modules\request\request.js:185:22)
at Request.emit (events.js:310:20) {
code: 'ERR_HTTP_INVALID_STATUS_CODE'
 }
[nodemon] app crashed - waiting for file changes before starting...

这里有什么问题?有人可以帮我知道吗

以下是请求电话:-

     request.post(url, {
        body :req_body,
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${access_token}`
        }

    }, (error, res, body) => {
        if (error) {
            console.log('An error occured while loading the page', error)
            return
        }

        let data = JSON.parse(body);
        console.log("export data", data);
        console.log("export call:", data)
        response.send("exporting started", data)

        }
4

2 回答 2

0

阅读错误信息的第一行:

express deprecated res.send(status, body): 改用 res.status(status).send(body)

现在看看你打电话的地方send

response.send("exporting started", data)

您将两个参数传递给send,但文档显示它只接受一个参数。

曾经有一段时间它接受两个参数,但即便如此,第一个参数也需要是 HTTP 状态码,而字符串"exporting started"不是。

于 2020-06-08T09:27:34.683 回答
-1

你应该使用res.status(status).send(body)而不是res.send(status, body)

于 2020-06-08T09:28:50.713 回答