1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| const Encrypt = require('./crypto.js'); const http = require('http'); function createWebAPIRequest(host, path, method, data, cookie, callback, errorcallback) { let music_req = ''; const cryptoreq = Encrypt(data); const http_client = http.request({ hostname: host, method: method, path: path, headers: { 'Accept': '*/*', 'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Referer': 'http://music.163.com', 'Host': 'music.163.com', 'Cookie': cookie, 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36',
}, }, function (res) { res.on('error', function (err) { errorcallback(err) }); res.setEncoding('utf8'); if (res.statusCode !== 200) { createWebAPIRequest(host, path, method, data, cookie, callback);
} else { res.on('data', function (chunk) { music_req += chunk }); res.on('end', function () { if (music_req === '') { createWebAPIRequest(host, path, method, data, cookie, callback); return } if (res.headers['set-cookie']) { callback(music_req, res.headers['set-cookie']) } else { callback(music_req) } }) } }); http_client.write('params=' + cryptoreq.params + '&encSecKey=' + cryptoreq.encSecKey); http_client.end() }
|