【http】
2013-11-23 21:13
344 查看
var qs = require('querystring') require('http').createServer(function(req, res) { //res.writeHead(200, {'Content-Type': 'image/png'}) /*var stream = require('fs').createReadStream('image.png') stream.on('data', function(data) { res.write(data) }) stream.on('end', function() { res.end() })*/ //require('fs').createReadStream('image.png').pipe(res) if ('/' == req.url) { res.writeHead(200, {'Content-Type': 'text/html'}) res.end([ '<form method="POST" action="/url">', '<input type="text" name="name">', '<button>Submit</button>', '</form>' ].join('')) } else if ('/url' == req.url && 'POST' == req.method) { var body = '' req.on('data', function(data) { body += data }) req.on('end', function() { res.writeHead(200, {'Content-Type': 'text/html'}) res.end('Content-Type: ' + req.headers['content-type'] + 'Data:' + qs.parse(body).name) }) } else { res.writeHead(200, {'Content-Type': 'text/html'}) res.end('Not Found') } }).listen(3000) console.log(qs.parse('name=Guillermo'))
相关文章推荐
- WinSock初学入门:实现TCP服务器
- HttpComponents —— HTTP上下文环境(HttpContext)
- 2-7. HttpClient
- HttpURLConnection 与 Socket
- 网络编程1. 套接字编程基本知识
- TCP/IP网路协议复习
- 奇偶ACL的网络号匹配
- 通过setImageURI设置网络上面的图片
- C#版异步TCP聊天服务器端简单代码示例
- 网络U盾升级?是钓鱼网站下套!
- 卷积神经网络CNN
- 请妥善保管自己的QQ等网络帐号
- 请妥善保管自己的QQ等网络帐号
- 请妥善保管自己的QQ等网络帐号
- ASP.NET中使用HttpWebRequest调用WCF
- 网络广告行业资料整理
- 网络广告行业资料整理
- 网络广告行业资料整理
- 对于System.Net.Http的学习(一)——System.Net.Http 简介
- 站长们有注意过自己旁边的营销模式吗?