NodeJs post xml info

var request = require('request'),
  util = require('util'),
  commonUtil = require('/utils/common-util'),
  securityUtil = require('/utils/security-util');

var params = {
  app_id: 100,
  scene_id: 1,
  open_id: 'xxxx',
  subscribe_time: commonUtil.now()
};
var appKey = 'xxxxxx';
var sign = Object.keys(params).map(function(k) {
  return util.format('%s=%s', k, params[k]);
}).join('&') + appKey;
params.sign = securityUtil.genMD5(sign);

var postData = '<xml>';
postData += Object.keys(params).map(function(k) {
  return util.format('<%s>%s</%s>', k, params[k], k);
}).join('') + '</xml>';

var options = {
  url: 'xxx.do',
  headers: {
    'Content-Type': 'text/xml'
  },
  body: postData
};

request.post(options, function(err, res, html) {
  console.log(html);
});

 

你可能感兴趣的:(每天进步一点点,学习永无止境,nodejs,纵观千象,乔乐共享)