关于img图片response的问题
来源:3-8 HTTP长连接

慕用0863198
2020-01-10
const http = require(‘http’);
const fs = require(‘fs’);
http.createServer(function (request,response) {
console.log(‘request come’,request.url);
const html = fs.readFileSync('test.html','utf8');
const img = fs.readFileSync('test.jpg');
if(request.url === '/'){
response.writeHead(200,{
//如果将'Content-Type': 'text/html'变成text/plain,
// 那么就会在页面上出现html源码,浏览器不会对html的代码结构进行解析
'Content-Type': 'text/html'
});
response.end(html);
}else {
response.writeHead(200,{
//这里直接返回一个图片
'Content-Type': 'image/jpg'
});
response.end(img);
}
}).listen(8888);这里是先判断url为’/'的情况,这里直接就返回了html的代码,请问这里是读取到img的src了然后会判断为else的情况进行图片的返回嘛?
写回答
1回答
-
html加载之后浏览器会发起图片的请求
00
相似问题