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请求
浏览路径:https://www.cdcxhl.com/article36/isghpg.html

成都网站建设公司_创新互联,为您提供关键词优化网站策划软件开发云服务器定制开发网站排名

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

搜索引擎优化