首页 > 解决方案 > 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>

标签: phpcurlxampphostresolve

解决方案


推荐阅读