php - xampp curl 无法解析主机
问题描述
我通过 xampp 在 Windows 机器上托管应用程序。我创建了一个自定义网址。在 windows 主机文件中编辑它和 xampp httpd-vhosts.conf 应用程序正在运行。
但是当我尝试对 url 进行 curl 调用时,我收到错误无法解析主机:test.localhost
我究竟做错了什么?
这是我的电话:
$url = 'test.localhost/api_call';
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
// curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
这是 httpd-vhosts.conf 中的设置
<VirtualHost *>
# Pfad muss angepasst werden
DocumentRoot C:\xampp\htdocs/sites
ServerName localhost
</VirtualHost>
<VirtualHost *>
# Pfad verweist auf Projekt-Ordner
DocumentRoot "C:\xampp\htdocs/sites/test"
ServerName test.localhost
DirectoryIndex index.php
<Directory "C:\xampp\htdocs/sites/test">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
解决方案
推荐阅读
- d3.js - 在 d3 中显示/隐藏元素
- vespa - Vespa 是否支持选定检索的场投影?
- ruby-on-rails - 在 Hotwire/Rails 应用程序中,如何强制表单助手只接受文本/html?
- glsl - WebGL GLSL 放大 2D 图
- javascript - 强制 saga 在推送和延迟不起作用之前等待 API 返回
- sql - 使用 PL/SQL 的下一个和上一个动态操作
- java - 如果一个类正在创建另一个类的类型的数组,那么在 OOP 方面有什么关系?(聚合,组合)
- linux - 如何在 linux/bash/unix 中查找日期时间之间经过的 UTC 24 小时?
- latex - 将 LaTeX 方程转换为 SymPy [Julia] 格式
- jquery-mobile - Jquery 从外部文件加载弹出窗口