有没有办法为节点js https请求设置源端口? [英] Is there a way to set the source port for a node js https request?

查看:213
本文介绍了有没有办法为节点js https请求设置源端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法为节点js https请求设置源端口?我不是询问目的地,而是询问源,即用于发送请求的端口。

Is there a way to set the source port for a node js https request? I am not asking about the destination, rather the source, ie the port used to send the request.

上下文是我试图从特定端口发送https请求而不是随机端口,因此允许锁定iptables。节点未以root身份运行,因此端口不是443。

The context is I am trying to send https requests from a specific port, rather than random ports, thus allowing for locking down iptables. Node is not running as root, thus the port is not 443.

更新:
看来Node中存在错误。选项localAddress和localPort不起作用,至少使用TLS套接字。

Update : It appears there is a bug in Node. The options localAddress and localPort do not work, at least with a TLS socket.

更新:
从去年发现了类似的问题。答案是不要那样做,这似乎是愚蠢的,因为该节点被认为是一个通用工具。 Nodejs TCP连接客户端端口分配

推荐答案

不幸的是,看起来Node不支持绑定客户端端口。显然,这不是一个使用很多的功能,但它是可能的。此链接相当好地解释了端口绑定。 https://blog.cloudflare.com/cloudflare-now-supports-websockets/不确定如何让nodejs的人考虑这一变化。

Unfortunately it looks like Node does not support binding a client port. Apparently this isn't a feature that is used much, but it is possible. This link explains port binding fairly well. https://blog.cloudflare.com/cloudflare-now-supports-websockets/ Not sure how to get the nodejs people to consider this change.

这篇关于有没有办法为节点js https请求设置源端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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