使用curl从Homestead来宾VM内访问主机
我正在尝试使用curl 从 Homestead VM 中访问在我的主机上运行的 api url。当我从来宾虚拟机中执行代码时,它返回错误 无法连接到 10.0.2.15 端口 8001:连接被拒绝
,10.0.2.15
是主机的 IP客人里面。我怀疑必须在端口转发中找到解决方案,我已尝试在 Homestead.yml
内进行端口转发,但它没有解决问题。
这是卷曲调用。
$defaultParams = array(
CURLOPT_HEADER => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLINFO_HEADER_OUT => TRUE,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => $this->apiKey.':',
CURLOPT_HTTPHEADER => array( 'Expect:' ),
CURLOPT_FAILONERROR => true
);
$url = 'http://10.0.2.15:8001/api/languages?display=full&ws_key=xxxxx';
$session = curl_init($url);
...
如果我访问主机上的网址,我会得到预期的结果:
I'm trying to access api url which runs on my host machine from within a Homestead VM with curl. When I execute the code from within the guest VM it returns the error Failed to connect to 10.0.2.15 port 8001: Connection refused
, 10.0.2.15
is the ip of the host inside the guest. I suspect the solution must be found in port forwading, I have tried port forwarding inside Homestead.yml
but it did't resolve the issue.
This is the curl call.
$defaultParams = array(
CURLOPT_HEADER => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLINFO_HEADER_OUT => TRUE,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => $this->apiKey.':',
CURLOPT_HTTPHEADER => array( 'Expect:' ),
CURLOPT_FAILONERROR => true
);
$url = 'http://10.0.2.15:8001/api/languages?display=full&ws_key=xxxxx';
$session = curl_init($url);
...
If I access the url on the host I get the expected result:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论