【问题标题】:Curl GET from vagrant nodejs. The requested URL could not be retrieved from requested server来自 vagrant nodejs 的卷曲 GET。无法从请求的服务器检索请求的 URL
【发布时间】:2017-01-10 22:27:56
【问题描述】:

尝试从 nodeJS vagrant virtual box 运行以下 curl 命令。

本地主机的 IP 地址 - 10.29.12.152

卷曲http://10.29.12.152:3002/api/v1/suggest/zeta-spot-cms/documents?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9CJyfw&term=xfinity

而且,我还使用 expressJS 开发了列表 API 端点。

如果我在 Web 浏览器中运行上述 API 端点,它将从本地环境中获取结果。

[
{
_index: "zeta-spot-cms",
_type: "documents",
_id: "AVmCw40nHO6bFVnpAj-5",
_score: 1,
_source: {}
}
]

尝试将此 API 用作 vagrant 虚拟框中的 curl 命令。我收到以下错误。

<div id="titles">
<h1>ERROR</h1>
<h2>The requested URL could not be retrieved</h2>
</div>
<hr>

<div id="content">
<p>The following error was encountered while trying to retrieve the URL: <a href="http://10.29.12.152:3002/api/v1/suggest/zeta-spot-cms/documents?">http://10.29.12.152:3002/api/v1/suggest/zeta-spot-cms/documents?</a></p>

<blockquote id="error">
<p><b>Connection to 10.29.12.152 failed.</b></p>
</blockquote>

<p id="sysmsg">The system returned: <i>(113) No route to host</i></p>

<p>The remote host or network may be down. Please try the request again.</p>

您能否建议我,如何在 vagrant 虚拟框中提高 curl 命令以获取 localhost 的结果。

提前致谢!

【问题讨论】:

    标签: node.js curl vagrant


    【解决方案1】:

    我有点难以准确理解你在问什么,所以让我先澄清一下——我将你的问题解释为你有一个由 Vagrant 管理的 virtualbox VM,并且你有一个 node.js 应用程序在该虚拟机内运行。当您通过(主机系统的)浏览器访问应用程序时,您会得到预期的结果。但是,当您尝试从 VM 内部使用 curl 时,您会收到上面复制的“没有到主机的路由”错误。

    假设这一切都是正确的,我认为答案很简单。我猜 virtualbox VM 不知道它的 IP 地址是 10.29.12.152。因此,从 VM 内部运行的命令不知道如何访问该 IP 地址。根据您的描述,我也不清楚该 IP 是否来自。

    如果我的假设是正确的,您应该能够将 10.29.12.152 替换为 127.0.0.1 并且该命令应该可以工作。

    进一步的故障排除技术是在命令行上运行ifconfig,然后查看显示的 IP 地址。

    【讨论】:

    • 感谢@Geoff Gerrietts 的快速响应,Nodejs 应用程序未在 virtualbox VM 中运行。在本地机器(10.29.12.152)中运行。我想在 virtualbox VM 中运行 curl 命令。如果我给出 127.0.0.1 而不是 IP 地址,我得到 curl: (7) could't connect to host 错误。
    • 其实我想在另一个运行在virtualbox VM中的应用程序中调用这个API
    • 我还用虚拟机中的 ping 命令进行了检查。结果如下:PING 10.29.12.152 (10.219.162.152) 56(84) 字节数据。来自 10.29.12.152 的 64 个字节:icmp_seq=1 ttl=63 time=0.361 ms 来自 10.29.12.152 的 64 个字节:icmp_seq=2 ttl=63 time=0.296 ms
    • 节点应用可能没有绑定地址?
    猜你喜欢
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    • 2017-11-16
    相关资源
    最近更新 更多