Skip to content

Instantly share code, notes, and snippets.

@lkLeonov
Last active December 8, 2016 09:46
Show Gist options
  • Save lkLeonov/11ca04d94e990c1649781a8a85009e30 to your computer and use it in GitHub Desktop.
Save lkLeonov/11ca04d94e990c1649781a8a85009e30 to your computer and use it in GitHub Desktop.
'use strict'
const http = require('http');
const querystring = require('querystring');
const PORT = 80;
http.createServer((servReq, servRes) => {
const postData = querystring.stringify({
act:'load_idols',
al:1,
oid:50595075
});
const postReqOptions = {
hostname: 'vk.com',
path: '/al_fans.php',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData),
"origin":"http://vk.com"
}
};
const postReq = http.request(postReqOptions, (res) => {
console.log('SERVER::POST: ' + postReqOptions.hostname + postReqOptions.path, res.statusCode);
let vkData = '';
res.on('data', (chunk) => {
vkData += chunk;
});
res.on('end', () => {
console.log('DATA: ' + vkData)
servRes.writeHeader(200, {"Content-Type": "application/json"});
servRes.end(vkData)
});
});
postReq.write(postData);
postReq.end();
}).listen(PORT);
console.log(`SERVER:: Listening on port ${PORT} ...`);
// helpers
// first matched group in regex
function reFirstGroup (re, str) {
var match = re.exec(str);
var arr = [];
if (match && match[1]) arr.push(match[1])
while (match != null) {
match = re.exec(str);
if (match && match[1]) arr.push(match[1])
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment