-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
49 lines (39 loc) · 936 Bytes
/
demo.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
42
43
44
45
46
47
48
49
var http=require('http');
var body = {
"data":{
"channel" : "aaa",
"appkey" : "bbb"
},
"sign" : "22334455",
"token" : "bb667788"
};
var bodyString = JSON.stringify(body);
var headers = {
'Content-Type': 'application/json',
'Content-Length': bodyString.length
};
var options = {
host: '127.0.0.1',
port: 3005,
path: '/Config',
method: 'POST',
headers: headers
};
var req=http.request(options,function(res){
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
responseString += data;
});
res.on('end', function() {
//这里接收的参数是字符串形式,需要格式化成json格式使用
var resultObject = JSON.parse(responseString);
console.log('-----resBody-----',resultObject);
});
req.on('error', function(e) {
// TODO: handle error.
console.log('-----error-------',e);
});
});
req.write(bodyString);
req.end();