Request for Cielo with node.js

0

You are giving the following error code:

TypeError: First argument must be a string or Buffer

My code looks like this:

        request: function (dataJson, callback) {

        var options = {
            hostname: 'apisandbox.cieloecommerce.cielo.com.br',
            port: 443,
            secureProtocol: 'TLSv1_method',
            encoding: 'utf-8',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Accept': 'application/json',
                'Accept-Charset': 'utf-8',
                'Content-Length': 0
            },
            method: 'POST'
        };

        if (ambienteDeProducao || false) {
            options.hostname = 'api.cieloecommerce.cielo.com.br';
        }

        var postData = dataJson;
        options.headers['Content-Length'] = Buffer.byteLength(postData);
        var req = https.request(options, function (res) {
            var data = [];
            res.on('data', function (chunk) {
                data.push(chunk);
            });
            res.on('end', function () {
                callback(null, data.join(''))
            });
        });
        req.write(postData);
        req.end();
    }

I do not know what can be

    
asked by anonymous 06.11.2017 / 17:08

0 answers