RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
node.js以post请求方式发送http请求
var http = require('http');
var querystring = require('querystring');
// 请求参数
var postData = querystring.stringify({
    'name': "wangbin",
    'password': "123456",
    'serverId': 2
});
var options = {
  hostname: '192.168.1.135',
  port: 3001,
  path: '/login',
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': postData.length
  }
};
var req = http.request(options, function(res) {
  res.setEncoding('utf8');
  var resData = [];
  res.on('data', function (chunk) {
    resData.push(chunk);
  });
  res.on('end', function() {
    var data = resData.join("");
    console.log(data);
  })
});
req.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});
// 发送请求
req.write(postData);
req.end();

网站名称:node.js以post请求方式发送http请求
文章出自:http://cqwzjz.cn/article/isghpg.html