2016-11-29 245 views
0

我想在.then()内做一个http帖子。我已经以许多不同的方式...没有任何工作 我试图创建一个用户,然后做一个http POSThttp post .then()

'use strict'; 

module.exports = function(app) { 
return function(req, res, next) { 
const body = req.body; 

// Get the user service and `create` a new user 
app.service('users').create({ 
    email: body.email, 
    password: body.password 
}).then('I WANT HTTP POST WITH PARAMS HERE') 
// On errors, just call our error middleware 
.catch(next); 

}; 
}; 

我想在POST

回答

2

发送电子邮件和密码,您可以在承诺链返回的承诺。我会使用promisified请求在这里做postAsync。

var Promise = require('bluebird') 
var request = Promise.promisifyAll(require('request')) 

app.service('users').create({ 
     email: body.email, 
     password: body.password 
    }).then(function(createUserResp) { 
     return request.postAsync(/**/) 
    }) 
    }).then(function(resp) { 
     // do sth 
    }) 
    .catch(next); 
0
var RP = require('request-promise') 

app.service('users').create({ 
    email: body.email, 
    password: body.password 
}).then(function() { 
    var opt = { 
     url: 'targetUrl', 
     formData: { 
      email: body.email, 
      password: body.password 
      //, json: true // if result is in json format 
     } 
    } 
    return RP.post(opt) 
}).then(function (postResult) { 

}) 
.catch(next);