Razyshen
V2EX  ›  Node.js

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

  •  
  •   Razyshen · Sep 20, 2015 · 4503 views
    This topic created in 3887 days ago, the information mentioned may be changed or developed.
    服务器使用 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 版本的问题吗?
    Supplement 1  ·  Sep 24, 2015
    提问关闭,原因是在 nginx 的配置问题
    5 replies    2015-09-21 12:50:46 +08:00
    rekey
        1
    rekey  
       Sep 21, 2015
    有没有 \n 之类的字符被你提前解析了?

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

    Content-Encoding: Gzip
    Razyshen
        4
    Razyshen  
    OP
       Sep 21, 2015
    @newghost 有的
    Razyshen
        5
    Razyshen  
    OP
       Sep 21, 2015
    @rekey Response Content-Type:application/json; charset=utf-8
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3185 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 14:28 · PVG 22:28 · LAX 07:28 · JFK 10:28
    ♥ Do have faith in what you're doing.