gpt4 book ai didi

node.js - 如何在 Axios 调用中从 Node 检索远程 IP 地址

转载 作者:太空宇宙 更新时间:2023-11-04 00:17:52 25 4
gpt4 key购买 nike

当我在 Node.js 中进行 axios 调用时,我想获取远程 url 的已解析 IP 地址。请参阅下面的***评论。预先非常感谢!

axios.get('http://www.example.com')
.then(function (response) {
// *** How can I get the resolved IP address of www.example.com here
})
.catch(function (error) {
console.log(error);
});

最佳答案

Axios 文档指出 response.request “是 node.js 中的最后一个 ClientRequest 实例(在重定向中)。”

axios.get('http://www.example.com')
.then(function (response) {
console.log(response.request.socket.remoteAddress);
});

关于node.js - 如何在 Axios 调用中从 Node 检索远程 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45989401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com