使用浏览器端口打开HTML

来源:互联网 发布:seo超级伪静态 编辑:程序博客网 时间:2024/06/04 19:00

第一步:HTML

<!doctype html><html>    <head>        <title>College Task</title>        <meta charset="utf-8" />    </head>    <script>    </script>    <body>        <form action='http://localhost:8080/'  method='post'><br />            Name: <input type='text' name='name' value='Mowen_Yi' /><br />            Pass: <input type='password' name='pass' value='123456' />            <input type='submit' value='Submit' />        </form>    </body></html>

第二步:服务器

var fs=require('fs');var http=require('http');var server=http.createServer(function(req,res){    var html=fs.readFileSync('index.html');    res.writeHead(200,{'Content-Type':'text/html'});    res.write(html);    res.end();}).listen(8080,function(){    console.log('Server is running');});

将服务器运行之后,在端口打开HTML结果如下:

原创粉丝点击