这是我的离子代码
dialogflow(question) {
let headers = new Headers();
headers.append('Content-Type','application/json');
return this.http.post('http://localhost:3000/api/dialogflow',question,{headers: headers})
.map(res => res.json());
}
在控制台日志中,我收到错误消息
POST http://localhost:3000/api/dialogflow 400(错误请求) 这是来自路由文件(后端)
router.post('/dialogflow', function(req,res) {
console.log('reached here');
在后端(平均)控制台中,它抛出错误
SyntaxError: Unexpected token h in JSON at position 0
at JSON.parse (<anonymous>)
at createStrictSyntaxError (D:\product\project-1\node_modules\body-parser\lib\types\json.js:158:10)
at parse (D:\product\project-1\node_modules\body-parser\lib\types\json.js:83:15)
at D:\product\project-1\node_modules\body-parser\lib\read.js:121:18
at invokeCallback (D:\product\project-1\node_modules\raw-body\index.js:224:16)
at done (D:\product\project-1\node_modules\raw-body\index.js:213:7)
at IncomingMessage.onEnd (D:\product\project-1\node_modules\raw-body\index.js:273:7)
at emitNone (events.js:106:13)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
我该如何解决?
答案 0 :(得分:1)
要发送的对象未正确序列化。
at JSON.parse (<anonymous>)
at createStrictSyntaxError (D:\product\project-1\node_modules\body-parser\lib\types\json.js:158:10)
at parse (D:\product\project-1\node_modules\body-parser\lib\types\json.js:83:15)