V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Razyshen
V2EX  ›  Node.js

nodejs 服务器数据丢失,客户端 json 解析失败

  •  
  •   Razyshen · 2015-09-20 15:50:38 +08:00 · 3706 次点击
    这是一个创建于 3139 天前的主题,其中的信息可能已经有所发展或是发生改变。
    服务器使用 node express + nginx 搭建的
    做的 restful 接口服务器,但是最近发现部分接口
    本来正常的返回是举例{status:'ok',data:{a:'1',b:'2'}}
    现在的返回有概率性返回 {status:'ok',data: 后面就没有了数据就丢失了,导致客户端 json 解析失败。
    node 0.10.35
    express 4
    在 node 上使用的 express 的 gzip 压缩
    我能想到的原因只有 gzip 压缩出的问题,考虑把 gzip 压缩放到 nginx 层做。但是好像并没有解决问题。
    是 node 版本的问题吗?
    第 1 条附言  ·  2015-09-24 16:47:21 +08:00
    提问关闭,原因是在 nginx 的配置问题
    5 条回复    2015-09-21 12:50:46 +08:00
    rekey
        1
    rekey  
       2015-09-21 10:39:01 +08:00
    有没有 \n 之类的字符被你提前解析了?

    返回的 headers 要写明是 json/application 之类的,否则你用浏览器验证的时候也是有可能有问题的。
    fatelei
        2
    fatelei  
       2015-09-21 10:46:57 +08:00
    看看 Content-Length ,是否是正确的。
    newghost
        3
    newghost  
       2015-09-21 11:18:51 +08:00
    看看 response 有没有这个 header ,否则浏览器无法解压

    Content-Encoding: Gzip
    Razyshen
        4
    Razyshen  
    OP
       2015-09-21 12:49:26 +08:00
    @newghost 有的
    Razyshen
        5
    Razyshen  
    OP
       2015-09-21 12:50:46 +08:00
    @rekey Response Content-Type:application/json; charset=utf-8
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1988 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 16:16 · PVG 00:16 · LAX 09:16 · JFK 12:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.