nodejs调用图灵机器人接口

586 查看

var post_data = quetystring.stringify({
  key: '图灵机器人key',
  info: 需要发送的信息,
  userid: 用户id(可选)
});
var options = {
  host: 'www.tuling123.com',
  port: 80,
  path: '/openapi/api',
  method: 'POST',
  rejectUnauthorized: false,
  headers: {
    "Content-Type": 'application/x-www-form-urlencoded', //这个一定要有
  }
};
var req = http.request(options, function (res) {
  console.log('STATUS: ' + res.statusCode);
  console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});
req.write(post_data);
req.end();