如何使用node-rest-client查看原始HTTP请求和原始HTTP响应

时间:2015-11-13 18:38:40

标签: node.js rest http

有没有办法查看完整的原始HTTP请求和响应以使调试更容易? 这是节点模块(https://www.npmjs.com/package/node-rest-client)和示例。

var Client = require('node-rest-client').Client;
client = new Client();

args = {
     path:{"p1":"1234", "p2":"abcd"}
     headers:{"Authorization":"01234567890"}
}

client.get("http://example.com/${p1}/${p2}", args, function(data, response){
            // parsed response body as js object 
            console.log(data);
            // raw response 
            console.log(response);
        }).on('error',function(err){
            console.log('something went wrong on the request', err.request.options);
        });

1 个答案:

答案 0 :(得分:0)

根据source codeClient.get()函数返回常规字符'请求对象由节点的httphttps模块创建(最终,在引擎盖下)。因此,请尝试检查client.get()的返回值并查看其中的内容。