flume http接口:
1.使用request模块
npm install request
代码
/********request提交请求*************/
var request = require('request');
var data = [{
"body":JSON.stringify([{
"userName": "Abel",
"singer": "one444477",
"location": "SH",
"userTime": 1491808978.90688,
"gender": "M",
"age": 27,
"devName": 1,
"share": 0,
"songName": "one",
"occupation": "IT222222"
}])
}];
request({
url: 'http://222.31.81.214:5140',
method: "POST",
json: true,
headers: {
"content-type": "application/json",
},
body: data
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log('----post--info------', data);
}else{
console.log(body);
}
});
2.使用request-json提交请求
npm install request-json
代码:
/********request-json提交请求*************/
requestjson = require('request-json');
var client =requestjson.createClient('http://222.31.81.214:5140',{"Content-type":"application/json"});
var data = [{
"body":JSON.stringify([{
"userName": "Abel",
"singer": "one444477",
"location": "SH",
"userTime": 1491808978.90688,
"gender": "M",
"age": 27,
"devName": 1,
"share": 0,
"songName": "one",
"occupation": "IT"
}])
}];
client.post('/', data,function(err, res, body) {
return console.log(body);
});
注:一定要将提交的json字符串放在body里面
网友评论