Created
January 5, 2016 08:10
-
-
Save ghostoy/28f6dcec8b4bfb18bc30 to your computer and use it in GitHub Desktop.
Post Form
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>form post</title> | |
</head> | |
<body> | |
<form method="POST" action="http://localhost:9999/post.html"> | |
<input type="text" name="myfield" value="myvalue"> | |
<button type="submit">Submit</button> | |
</form> | |
</body> | |
</html> |
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
{ | |
"name": "form-post", | |
"main": "index.html", | |
"bg-script": "server.js" | |
} |
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 server = http.createServer(); | |
server.on('request', function(req, res) { | |
console.log(req.url); | |
if (req.url === '/post.html') { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.write('method: ' + req.method + '\n'); | |
req.on('data', function(data) { | |
res.write(data); | |
}); | |
req.on('end', function() { | |
res.end(); | |
}); | |
} else { | |
res.writeHead(404, {'Content-Type': 'text/plain'}); | |
res.end('Page not found'); | |
} | |
}); | |
server.listen(9999); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment