-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathpostdemo.js
41 lines (37 loc) · 866 Bytes
/
postdemo.js
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
var http=require('http');
var querystring = require('querystring');
var postData ={
'csrf_token': "",
's': "王菲",
'type':1,
'offset':0,
'limit':5,
'total':true
};
var options = {
method: "POST",
host: "music.163.com",
port: 80,
path: "/api/search/get/web",
headers: {
"Content-Type": 'application/x-www-form-urlencoded',
'Referer': 'http://music.163.com/search/'
}
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
var resData = [];
res.on('data', function (chunk) {
resData.push(chunk);
});
res.on('end', function() {
var data = resData.join("");
console.log(JSON.parse(data));
})
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// 发送请求
req.write(querystring.stringify(postData));
req.end();