"Unexpected end of input" message on response from simple POST request to node.js

I've written a simple node.js program to demonstrate the problem I'm running into elsewhere. Given the following node.js program: var http = require('http'); http.createServer(function (req, res) { // simple repro for json deserializaiton error cause by right quote character '’' var json = { 'foo': 'bar’s answer' }; var write = JSON.stringify(json); res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': write.length }); res.end(write); }).listen(8085, '127.0.0.1'); When I use chrome's Advanced Rest Client to POST to this, I get back a 200 OK response, but in the JSON tab of the response's content, the term "unexpected end of input" appears instead of the parsed json. In the raw tab, the string "{"foo":"bar’s answer" is displayed, making it apparent why the json was unable to be parsed (it's missing the closing '}'). If I remove the '’' from the original object, the response parses just fine when it returns. Any idea why a simple '’' causes the json to fail to be parsed? I've ran into the same problem with various other characters in my testing.

以上就是"Unexpected end of input" message on response from simple POST request to node.js的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏