0

我想在里面做一个http post .then()。我已经以许多不同的方式使用它...没有任何效果我正在尝试创建用户并POST在创建后执行 http。

'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

4

2 回答 2

2

你可以在 Promise 链中返回一个 Promise。我会在这里使用承诺请求来执行 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);
于 2016-11-29T04:12:24.187 回答
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);
于 2016-11-29T04:22:04.730 回答