HTTP协议

$ telnet www.google.com 80
Trying 74.125.204.106...
Connected to www.google.com.
Escape character is '^]'.
GET  /index.html HTTP/1.1

HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: http://www.google.com.hk/index.html?gfe_rd=cr&dcr=0&ei=8LX6WZuALNCi4wKSjLW4Cw
Content-Length: 282
Date: Thu, 02 Nov 2017 06:06:40 GMT

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com.hk/index.html?gfe_rd=cr&amp;dcr=0&amp;ei=8LX6WZuALNCi4wKSjLW4Cw">here</A>.
</BODY></HTML>

302 Found,原始描述短语为 Moved Temporarily


NodeJS

事件驱动,单进程单线程,异步实现,events模块

var util = require('util');
var fs = require('fs');
function readFile(str, callback){
var lines =[];
fs.readFile(str, function (err, data) {
 if (err) throw err;
 lines.push(data);
 console.log(data.toString());
});
callback(lines);
}
var a, b ;
readFile('./20.txt', function(data){a= data;});
readFile('./10.txt',function(data){b= data;});
util.log("a"+ a);
util.log("b" +b);

同步

var util = require('util');
var fs = require('fs');
function readFile(str, callback){
 var lines =[];
 result = fs.readFilesync(str) {
  lines.push(data);
  console.log(data.toString());
});
callback(lines);
}
var a, b ;
readFile('./20.txt', function(data){a= data;});
readFile('./10.txt',function(data){b= data;});
util.log("a"+ a);
util.log("b" +b);

results matching ""

    No results matching ""