node.js以post请求方式发送http请求
2015-09-15 16:40
691 查看
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();本文出自 “mirwangsir” 博客,请务必保留此出处http://mirwangsir.blog.51cto.com/7723278/1695008
相关文章推荐
- iOS 9 HTTP不能正常使用的解决方法
- Vmware vSphere 5.0 vSphere网络原理及vSwitch简介
- XMLHttpRequest cannot load"url"Cross origin requests are only supported. send @ jquery-2.1.4.js:8630
- hdu5446(2015长春网络赛J题)
- 【网络】(十)select的限制与解决方法poll
- XMLHttpRequest cannot load – Origin is not allowed by Access-Control-Allow-Origin.
- Android开发:如何实现TCP和UDP传输
- 被动接口在rip,eigrp,ospf中的应用
- Android - 跳转系统网络设置
- http://bbs.phpcms.cn/thread-266337-1-1.html
- Android - 判断网络状态
- tcp窗口机制(写的最简单精炼的文章)
- Linux内存管理之mmap详解 http://blog.chinaunix.net/uid-26669729-id-3077015.html
- java apache commons HttpClient发送get和post请求的学习整理
- PHP接收客户端数据方式:post,HTTP_RAW_POST_DATA,input
- 网络请求框架---Volley
- iOS网络监测如何区分2、3、4G?
- Kickstart+HTTP+DHCP+TFTP全自动批量安装部署Linux系统
- HTTP 的应答码,错误码,通信码
- http连接池使用