使用特定的网络接口执行请求 [英] Perform request using specific network interface

查看:49
本文介绍了使用特定的网络接口执行请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用特定的网络接口在 NodeJS 中执行 GET/POST 请求?

Is it possible to perform GET/POST request in NodeJS using specific network interface?

即使用 CURL,我可以调用两个 POST 调用,例如:

I.e. with CURL I can invoke two POST calls like:

curl -X POST --interface wlan0 http://192.168.1.5/resource
curl -X POST --interface wlan1 http://192.168.1.5/resource
//                       ^^^^^

两个 IP 地址都是不同的机器 - 所以第一个 WiFi 模块连接到一个 SSID,第二个连接到一个非常不同的网络,但是由于一些最高要求,IP 是相等的(它们位于不同的、孤立的网络).

Both IP addresses are different machines - so first WiFi module is connected to one SSID, second is connected with a very different network, but the IPs are equal because of some top requirements (they lay in different, isolated networks).

推荐答案

查看 http 选项中的 localAddress 选项:

See the localAddress option in the http options:

您需要将其设置为用于给定接口的 IP 地址.

You need to set it to your IP address that is used for a given interface.

另一种选择是使用 node-curl:

这篇关于使用特定的网络接口执行请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆