node.js 学习第十四天 get/post
来源:互联网 发布:树莓派3b ubuntu mate 编辑:程序博客网 时间:2024/06/05 10:07
一、网络请求
var http=require('http');
var url=require('url');
var util=require('util');
//①、简单的网络请求
// http.createServer(function req (req,res) {
// res.writeHead(200,{'Content-Type':'text/plain'});
// //inspect 隐藏的信息
// res.end(util.inspect(url.parse(req.url,true)));
// }).listen(9999);
//②、获取url的参数
// http.createServer(function(req,res){
// res.writeHead(200,{'Content-Type':'text/plain'});
// //解析url
// var params=url.parse(req.url,true).query;
// res.write('name--->'+params.name+'\n');
// res.write('url--->'+params.url);
// res.end();
// }).listen(9999);
//post请求
var queryString=require('querystring');
var postHTML =
'<html><head><meta charset="utf-8"><title> Node.js 实例</title></head>' +
'<body>' +
'<form method="post">' +
'信息1: <input name="name"><br>' +
'信息2: <input name="url"><br>' +
'<input type="submit">' +
'</form>' +
'</body></html>';
http.createServer(function(req,res){
//postData的数据暂存信息
var postData='';
// 通过req的data事件监听函数,每当接受到请求体
//的数据,就累加到post变量中
req.on('data',function(chunk){
postData+=chunk;
});
//请求结束
req.on('end',function(){
postData=queryString.parse(postData);
// res.end(util.inspect(postData));
res.writeHead(200, {'Content-Type': 'text/html; charset=utf8'});
if(postData.name && postData.url) { // 输出提交的数据
res.write("信息1:" + postData.name);
res.write("<br>");
res.write("信息2:" + postData.url);
} else { // 输出表单
res.write(postHTML);
}
res.end();
})
}).listen(9999);
- node.js 学习第十四天 get/post
- Node.js GET/POST请求
- Node.js GET/POST请求
- Node.js GET/POST请求
- Node.js GET/POST请求
- Node.js GET/POST请求
- Node.js GET/POST请求
- Node.js GET/POST请求
- node.js处理get和post请求
- node.js处理get、post数据
- Node.js中Get和Post处理
- Node.js GET与POST请求
- Node.js GET/POST请求简单例子
- node.js中get和post请求
- node.js发送http(get,post)请求
- Node.js基础get post请求
- 程序学习第十四天
- .net学习第十四天
- PHP中or与||的区别
- linux上设置mysql编码
- testng+spring整合
- java学习第二十三天之GUI
- Linux学习教训(1 )——nano连入WIFI,但是无法正常上网。
- node.js 学习第十四天 get/post
- Android设计模式(七)-状态模式
- Angular2环境搭载中可能出现的问题及解决方法
- js方法验证字符串长度,中文算2个字符
- 使用yeoman快速搭建react-webpack开发环境
- 在 Kali Linux 中更改 GRUB2 背景的 5 种方式
- SuperMap iMobile for Android 三维开发指南
- Mybatis 与 枚举 实现自动转换
- json数据的问题