简体   繁体   English

Node.js Web请求到外部服务器

[英]Node.js web request to external server

I'm working on a nodejs project, and I've found something that I can't afford. 我正在开发一个nodejs项目,但发现了一些我买不起的东西。 In a single moment, my nodejs application needs to ask something to another webserver. 在一瞬间,我的nodejs应用程序需要向另一个Web服务器询问问题。 This web is a javascript application. 该网站是一个javascript应用程序。 It receives an string and answers with another string. 它接收一个字符串并回答另一个字符串。

How can I implement this in nodejs, or which modules do I need. 如何在nodejs中实现此功能,或者需要哪些模块。

The schema is something like this 模式是这样的

Nodejs --------> http://"webserver"/app.html?var=string Node.js --------> http://“ webserver” /app.html?var=string

^                                      |
|_______________string2________________| 

您可以通过此软件包发出HTTP请求-https: //www.npmjs.org/package/request或不发出HTTP请求-http://nodejs.org/api/http.html#http_http_request_options_callback

You can do a request using the HTTP module or use the Request Package to simplify things (Available using NPM ). 您可以使用HTTP模块发出请求,也可以使用请求包来简化操作(可使用NPM )。 Since these methods use callbacks like everything else in Node.js, you can easily carry on handling new incoming requests and only reply to that specific request once you received a response from the remote server. 由于这些方法与Node.js中的所有其他方法一样使用回调,因此您可以轻松地继续处理新的传入请求,并且仅在收到远程服务器的响应后才回复该特定请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM