正在显示
1 个修改的文件
包含
12 行增加
和
3 行删除
@@ -4,12 +4,21 @@ var http = require("http"); | @@ -4,12 +4,21 @@ var http = require("http"); | ||
4 | var uuid = require('uuid/v4'); | 4 | var uuid = require('uuid/v4'); |
5 | var URL = require('url'); | 5 | var URL = require('url'); |
6 | exports = module.exports = function (logger, settings) { | 6 | exports = module.exports = function (logger, settings) { |
7 | + | ||
8 | + | ||
9 | + function addParams(params) { | ||
10 | + var postData = !params ? '' : JSON.stringify(params || {}); | ||
11 | + return postData; | ||
12 | + } | ||
13 | + | ||
14 | + | ||
7 | /* | 15 | /* |
8 | * var options={ | 16 | * var options={ |
9 | 'host': 'xxx.xxx.xxx.xxx', | 17 | 'host': 'xxx.xxx.xxx.xxx', |
10 | 'port': 'xxxxx', | 18 | 'port': 'xxxxx', |
11 | 'path': '/uaa/v1/xxxxx', | 19 | 'path': '/uaa/v1/xxxxx', |
12 | 'method': 'POST', | 20 | 'method': 'POST', |
21 | + 'params':{}, | ||
13 | 'agent': false, | 22 | 'agent': false, |
14 | 'headers': { | 23 | 'headers': { |
15 | "Accept": "application/json", | 24 | "Accept": "application/json", |
@@ -20,9 +29,9 @@ exports = module.exports = function (logger, settings) { | @@ -20,9 +29,9 @@ exports = module.exports = function (logger, settings) { | ||
20 | } | 29 | } |
21 | */ | 30 | */ |
22 | 31 | ||
23 | - var client = function (options, success, fail) { | 32 | + var client = function (options) { |
24 | return new Promise(function (resolve, reject) { | 33 | return new Promise(function (resolve, reject) { |
25 | - var postData = !options.params ? '' : options.params; | 34 | + var postData = addParams(options.params); |
26 | var httpRequest = http.request(options, function (res) { | 35 | var httpRequest = http.request(options, function (res) { |
27 | var _data = ''; | 36 | var _data = ''; |
28 | res.setEncoding('utf8'); | 37 | res.setEncoding('utf8'); |
@@ -34,7 +43,7 @@ exports = module.exports = function (logger, settings) { | @@ -34,7 +43,7 @@ exports = module.exports = function (logger, settings) { | ||
34 | }); | 43 | }); |
35 | }); | 44 | }); |
36 | httpRequest.on('error', function (e) { | 45 | httpRequest.on('error', function (e) { |
37 | - reject(e); | 46 | + reject(_data, e); |
38 | }); | 47 | }); |
39 | httpRequest.write(postData); | 48 | httpRequest.write(postData); |
40 | httpRequest.end(); | 49 | httpRequest.end(); |
请
注册
或
登录
后发表评论