快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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://6mz.cn/article/isghpg.html

其他资讯