将POST页面中的HTML页面呈现给API

时间:2018-05-11 18:22:52

标签: javascript node.js http-post

我在尝试从api返回呈现的页面时遇到问题。

我试图通过帖子将数据从第一个应用程序发送到第二个应用程序。第二个应用程序应该接收数据,然后呈现第二个应用程序的第一页。

我有它发送和接收数据,但我无法获取要呈现的页面。

来自服务一的POST:

var request = require('request');
var rp = require('request-promise');


exports = module.exports = function (req, res) {

  var options = {
    method: 'POST',
    uri: 'http://localhost:3001/referral-service',
    body: {
      some: 'payload'
  },
    json: true // Automatically stringifies the body to JSON
};

rp(options)
    .then(function (parsedBody) {
        console.log(parsedBody);
    })
    .catch(function (err) {
        console.log('err')    
    });
};

服务中的api 2:

module.exports = function(router) {

  const bodyParser = require('body-parser');

      router.get('/', function(req, res, next) {
        res.render('welcome');
      });

    router.post('/referral-service', bodyParser.json(), function(req, 
    res, next) {

        res.render('welcome');
    });

};

0 个答案:

没有答案