Skip to content

Instantly share code, notes, and snippets.

@nazrdogan
Created June 20, 2017 23:17
Show Gist options
  • Save nazrdogan/7277b90d7499870fe6db5e247f54e9c1 to your computer and use it in GitHub Desktop.
Save nazrdogan/7277b90d7499870fe6db5e247f54e9c1 to your computer and use it in GitHub Desktop.
var data={ foo:"bar"};
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("OK");
}
};
xhttp.open("POST", "http://localhost:8080", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send(JSON.stringify(data));
var http = require('http');
http.createServer(function (req, res) {
res.write('Hello World!');
req.on('data', function (chunk) {
if (req.method == 'POST') {
console.log(chunk.toString());
}
});
res.end();
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment