从REST调用返回对象PUT打印垃圾值

时间:2016-08-30 14:05:53

标签: javascript node.js rest

我正在尝试使用PUT方法登录,并期望获得一些令牌。但我得到的回应打印垃圾值。代码块如下:

var Client = require('node-rest-client').Client;
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';

var client = new Client();

    var args = {
        headers: { "Content-Type": "application/json" },
        data: data_text
    };

    var req = client.put("https://wesite.com/api/web/Logon", args, function (data, response) {
        // parsed response body as js object

        console.log(data);
        // raw response
        //console.log(response);
       // Status code
       console.log(response.statusCode);
    });

    req.on('requestTimeout', function (req) {
    console.log('request has expired');
    req.abort();
    });

    req.on('responseTimeout', function (res) {
    console.log('response has expired');

    });

    //it's usefull to handle request errors to avoid, for example, socket hang up errors on request timeouts
    req.on('error', function (err) {
    console.log('request error', err);
    });

我得到的O / P是:

在0秒内完成 缓冲液3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 20 73 74 61 6e 64 61 6c 6f 6e 65 3d 22 79 .. 。 200

如何获取返回对象并以可读格式打印? 注意:JSON.stringify()没有帮助

0 个答案:

没有答案