{Nodejs} 错误 HPE_INVALID_CONSTANT 解决

今天遇到 HPE_INVALID_CONSTANT 错误.

 

{Nodejs} 错误 HPE_INVALID_CONSTANT 解决

 

1. 再现


 

今天下午调用同事的接口, 莫名出现该异常.一直在找原因.

以下是http.get 代码.. 没发现问题,且该方法调用其他接口没问题.

 http.get(_options.url, function (res) {

        var pageData = "";

        res.setEncoding(_options.encoding);

        res.on('error', function (err) {

            console.log(err);

        });

        res.on('data', function (chunk) {

            pageData += chunk;

        });

        res.on('end', function () {

            var content = pageData;

            callback(content);

        });

    }).on('error', function (e) {

        console.log(e.message);

        callback(null);

    });

 

2. 找原因

 


nodejs 相关资料中文的偏少, 一直在google. 看的是满头雾水. 

最后确定原因在于 同事的接口.

 

3. 解决


 

我比较了异常接口 和  正常接口, 才明白了为什么了.

以下是正常接口的 response 头信息

Connection:keep-alive Content-Encoding:gzip Content-Type:text/xml

Date:Thu, 08 May 2014 14:43:50 GMT Server:duomi/1.0.8

Transfer-Encoding:chunked

 

异常接口的 response 头信息

Connection:keep-alive Content-Encoding:gzip Content-Type:application/json

Date:Thu, 08 May 2014 14:37:47 GMT Server:duomi/1.0.8

Transfer-Encoding:chunked

 

最后看来确实是 Content-Type 属性作祟!

 

看来http请求接口如果 Content-Type 是json 会自动序列化成 json 对象??

 

 

你可能感兴趣的:(Invalid)