SQL 和 Postman 之间的连接不允许我发布日期

问题描述 投票:0回答:1

这是我的服务器的请求:

public async create(req: Request, res: Response): Promise<void> {
        await pool.query(`exec CrearUser @password = '${req.body.password }', @creationdate = '${req.body.creationdate}', @activestate  = '${req.body.activestate }', @modificationdate  = '${req.body.modificationdate }'`);
        console.log(req);
        res.json({ 'Text': 'User creado' });
    }

这是邮递员的帖子:

{
    "Password": "password5",
    "CreationDate": "01-01-2024",
    "ActiveState": true,
    "ModificationDate": null
}

但是当我发送帖子时,控制台告诉:

语法错误:意外的标记“”,...“tionDate”:null }" 不是有效的 JSON 在 JSON.parse() 解析时 (E:\Final Semestre\Server ode_modules ody-parser\lib ypes\json.js:89:19) 位于 E:\Final Semestre\Server ode_modules ody-parser\lib ead.js:128:18 在 AsyncResource.runInAsyncScope (节点:async_hooks:206:9) 在 invokeCallback (E:\Final Semestre\Server 颂歌模块 aw-body\index.js:231:16) 完成时(E:\Final Semestre\Server 颂歌模块 aw-body\index.js:220:7) 在 IncomingMessage.onEnd (E:\Final Semestre\Server 颂歌模块 aw-body\index.js:280:7) 在 IncomingMessage.emit (节点:事件:518:28) 在 endReadableNT(节点:内部/流/可读:1696:12) 在 process.processTicksAndRejections (节点:内部/进程/task_queues:82:21)

我知道问题出在 SQL Server,但我不知道如何修复它。

node.js sql-server postman
1个回答
0
投票

我不知道这里的错误是什么,但是从你的

SyntaxError
,我可以告诉你,当你从邮递员那里调用时,你的服务器正在尝试解析

{
    "Password": "password5",
    "CreationDate": "01-01-2024",
    "ActiveState": true,
    "ModificationDate": null
}

到对象。 但真正的问题是,你的输入数据本身就是一个对象,所以它无法执行

JSON.parse()
功能。

额外:如果您使用 Express 或类似的框架,我认为使用

body-parser
或一些熟悉的包在这种情况下可能会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.