node.js一次较完整的http请求过程展示
// 课时24request对象 // 课时25response对象 简单的http // 相对来说比较完整的客户端服务请求和数据交互过程 /* * 搭建一个http的服务器,用于处理用户发送的http请求 * 需要使用node提供一个模块 http */ // 加载一个http模块 var http = require('http'); // 通过http模块下的createserver创建并返回一个web服务器对象 var server = http.createserver(); server.on('error', function(err) { console.log(err); }); server.on('listening', function() { console.log('listening...'); }); server.on('request', function(req, res) { console.log('有客户端请求了'); // console.log(req); // res.write('hello'); // res.writehead 最好写在正文之前 res.writehead(200, 'linfei', { // 'content-type': 'text/plain' // 纯文本格式 'content-type': 'text/html; charset=utf-8' }); res.write('<h1>hello</h1>'); res.end(); // 必须在最后调用,不能省略 }) server.listen(8080, 'localhost');
如对本文有疑问, 点击进行留言回复!!
轻松解决 org.apache.taglibs.standard.tlv.JstlCoreTLV 困惑
vert实践五——Json?Protocol Buffer?FlatBuffers?
[基于tensorflow的人脸检测] 基于神经网络的人脸检测8——验证训练好的神经网络
selenium + ajax抓取英雄联盟全部英雄的详细信息及多线程保存全部皮肤图片到本地
网友评论