Skip to content

Instantly share code, notes, and snippets.

@ghostoy
Created January 5, 2016 08:10
Show Gist options
  • Save ghostoy/28f6dcec8b4bfb18bc30 to your computer and use it in GitHub Desktop.
Save ghostoy/28f6dcec8b4bfb18bc30 to your computer and use it in GitHub Desktop.
Post Form
<!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>
{
"name": "form-post",
"main": "index.html",
"bg-script": "server.js"
}
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