Last active
December 29, 2015 02:28
-
-
Save twmht/7600329 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Node.js-get</title> | |
</head> | |
<body> | |
<h1>Register page</h1> | |
<form id="signup" method="GET" action="http://localhost:5566/Signup"> | |
<label>username:</label><input type="text" id="username" name="username" /><br> | |
<label>email:</label><input type="text" id="email" name="email" /><br> | |
<input type="submit" value="register" /><br> | |
</form> | |
</body> | |
</html> |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Node.js-get</title> | |
</head> | |
<body> | |
<h1>Register page</h1> | |
<form id="signup" method="POST" action="http://localhost:5566/Signup"> | |
<label>username:</label><input type="text" id="username" name="username" /><br> | |
<label>email:</label><input type="text" id="email" name="email" /><br> | |
<input type="submit" value="register" /><br> | |
</form> | |
</body> | |
</html> |
This file contains hidden or 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
//Get example | |
var ip = "127.0.0.1"; | |
var port = 5566; | |
var http = require('http'); | |
var url = require('url') | |
http.createServer(function (req, res) { | |
var urlData = url.parse(req.url,true); | |
var action = urlData.pathname; | |
if(action === '/Signup'){ | |
var user = urlData.query; | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('hello '+user.username+',your email is '+user.email); | |
} | |
}).listen(port, ip); | |
console.log("Server running at http://" + ip + ":" + port); |
This file contains hidden or 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
//post example | |
var ip = "127.0.0.1"; | |
var port = 5566; | |
var http = require('http'); | |
var url = require('url') | |
var qs = require('querystring') | |
http.createServer(function (req, res) { | |
var urlData = url.parse(req.url,true); | |
var action = urlData.pathname; | |
if(action === '/Signup'){ | |
var formData = ''; | |
req.on('data',function(data){ | |
formData = formData+data; | |
}); | |
req.on('end',function(){ | |
//console.log(formData); | |
var user = qs.parse(formData); | |
//username = $username && email = $email | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('hello '+user.username+',your email is '+user.email); | |
}); | |
} | |
}).listen(port, ip); | |
console.log("Server running at http://" + ip + ":" + port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment