Last active
August 29, 2015 13:55
-
-
Save fabiob/8712212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var https = require('https'); // usar HTTPS ao invés de HTTP | |
var options = { | |
host: 'portal.consyste.com.br', | |
path: '/ws/cdlrio/contas', | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json', 'X-Consyste-Auth-Token': 'tey5CKdSrXtzr3pcc7fH' } | |
}; | |
var postData = { | |
"conta": { | |
"codigo": "teste1", | |
"nome": "CDLRio teste 1", | |
"ativa": true, | |
"empresas": [ { "cnpj": "12345678900", "nome": "Empresa teste1", telefone: "2123456" } ] | |
} | |
}; // no exemplo que você enviou, faltou fechar uma chave | |
var req = https.request(options) | |
.on('response', function(res) { | |
res.setEncoding('utf8'); | |
var data = ''; // é importante ler o retorno, para observar a mensagem de erro | |
res.on('data', function(chunk) { data += chunk; }); | |
res.on('end', function() { | |
if (res.statusCode == 200) | |
// sucesso, ler retorno | |
console.log(res.statusCode + " feito com sucesso: " + data); | |
else | |
// erro, tratar | |
console.log(res.statusCode + " feito com erro: " + data); | |
}); | |
}); | |
req.write(JSON.stringify(postData)); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment