zoukankan      html  css  js  c++  java
  • 【http】

    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'))
  • 相关阅读:
    code of C/C++(2)
    code of C/C++ (1)
    dll 的编写和使用
    Python基础练习-数据类型与变量part2
    Python基础练习-数据类型与变量
    python基础练习-循环
    Linux grep
    nginx反向代理
    正则表达式
    Linux samba ing
  • 原文地址:https://www.cnblogs.com/jzm17173/p/3439439.html
Copyright © 2011-2022 走看看