Created
November 16, 2012 08:03
-
-
Save dileephell/4085325 to your computer and use it in GitHub Desktop.
dileep css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var querystring = require('querystring'); | |
var util = require('util'); | |
http.createServer(function (req, res) { | |
// set up some routes | |
switch(req.url) { | |
case '/': | |
// show the user a simple form | |
console.log("[200] " + req.method + " to " + req.url); | |
res.writeHead(200, "OK", {'Content-Type': 'text/html'}); | |
res.write('<html><head><title>Hello Noder!</title></head><body>'); | |
res.write('<h1>Welcome to Trendstiger</h1>'); | |
res.write('<h2>Welcome to Trendstiger</h2>'); | |
res.write('<h2 style="color: red;">Welcome to Trendstiger</h2>'); | |
res.write('<form enctype="application/x-www-form-urlencoded" action="/formhandler" method="post">'); | |
res.write('Name: <input type="text" name="username" value="" /><br />'); | |
res.write('Age: <input type="text" name="userage" value="" /><br />'); | |
res.write('Company: <input type="text" name="usercompany" value="" /><br />'); | |
res.write('Profile: <input type="text" name="userprofile" value="" /><br />'); | |
res.write('Address: <input type="text" name="useraddress" value="" /><br />'); | |
res.write('<input type="submit" />'); | |
res.write('</form></body></html>'); | |
res.end(); | |
case '/formhandler': | |
if (req.method == 'POST') { | |
console.log("[200] " + req.method + " to " + req.url); | |
req.on('data', function(chunk) { | |
console.log("Received body data:"); | |
console.log(chunk.toString()); | |
}); | |
var fullBody = ''; | |
req.on('data', function(chunk) { | |
// append the current chunk of data to the fullBody variable | |
fullBody += chunk.toString(); | |
}); | |
req.on('end', function() { | |
// request ended -> do something with the data | |
res.writeHead(200, "OK", {'Content-Type': 'text/html'}); | |
// parse the received body data | |
var decodedBody = querystring.parse(fullBody); | |
// output the decoded data to the HTTP response | |
res.write('<html><head><title>Post data</title></head><body><pre>'); | |
res.write(util.inspect(decodedBody)); | |
res.write('</pre></body></html>'); | |
res.end(); | |
}); | |
} | |
} | |
}).listen(9049); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment