Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require("http");
- var url = require ("url");
- var qs = require('querystring');
- http.createServer(function(request, response) {
- console.log("Request...");
- var url_parts = url.parse(request.url, true);
- console.log(url_parts);
- if (url_parts.pathname == '/form'){
- response.writeHead(200, {"Content-Type": "text/html"});
- response.write('<form method="POST" action="/submit">');
- response.write('<input name="login">');
- response.write('<input name="password">');
- response.write('<input type="submit">');
- response.write('</form>');
- response.end();
- }
- if (url_parts.pathname == '/submit'){
- if(request.method=='GET'){
- response.writeHead(200, {"Content-Type": "text/plain"});
- response.write('Login: '+url_parts.query['login']+'\n');
- response.write('Password: '+url_parts.query['password']+'\n');
- response.end();
- }
- else if (request.method=='POST'){
- var body='';
- request.on('data', function(data){
- body+=data;
- });
- request.on('end', function(){
- var data = qs.parse(body);
- response.writeHead(200, {"Content-Type": "text/plain"});
- response.write('Post Login: '+data['login']+'\n');
- response.write('Post Password: '+data['password']+'\n');
- response.end();
- });
- }
- }
- }).listen(8080);
- console.log("Started");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement