将结果从Angular中的HTTP请求发送到NodeJS

时间:2021-10-24 11:43:46

I am currently sending a request from NodeJS to get some data, as such :

我目前正在发送NodeJS的请求以获取一些数据,如下:

In Angular :

在Angular中:

$http.post(API_ENDPOINT.url + '/annonce', {'link': url}).then(function (result) {
...
}

And in Node :

在Node中:

apiRoutes.post('/annonce', function (req, res) {
  const url = req.body.link

  request.get({
    uri: url,
    encoding: null
  }, function (error, response, html) {
    if (!error) {
      res.send(parser(url, html))
    }
  })

  return res
})

I would like to send this request from my front-end (Angular). I guess I could simply do the request like this :

我想从我的前端(Angular)发送此请求。我想我可以简单地做这样的请求:

$http.get(url).then(function(result)) {
    // send another post request to the back end with the result
}

but I've heard it was easier to use pipes in this case. Thing is, I really don't understand how to make it work. Can anyone help ?

但我听说在这种情况下使用管道更容易。事实上,我真的不明白如何让它发挥作用。有人可以帮忙吗?

1 个解决方案

#1


0  

If the page you are trying to retrieve does not have the CORS headers then angular will fail to make the request.

如果您尝试检索的页面没有CORS标题,则angular将无法发出请求。

If you expand on your usecase it should be easier to get you some help.

如果您扩展您的用例,应该更容易为您提供帮助。

#1


0  

If the page you are trying to retrieve does not have the CORS headers then angular will fail to make the request.

如果您尝试检索的页面没有CORS标题,则angular将无法发出请求。

If you expand on your usecase it should be easier to get you some help.

如果您扩展您的用例,应该更容易为您提供帮助。