php - cURL 错误 6:无法解析主机:test.example.localhost(参见 http://curl.haxx.se/libcurl/c/libcurl-errors.html)
问题描述
我正在尝试卷曲到我的本地主机 laravel 站点。我正在使用 XAMPP 7.1 当我尝试重新连接此代码时总是给出错误(而不是200 OK
响应)
致命错误:未捕获的 GuzzleHttp\Exception\ConnectException:cURL 错误 6:无法解析主机:test.example.localhost(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html) 在 D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:185 堆栈跟踪:#0 D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\ src\Handler\CurlFactory.php(149): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\ src\Handler\CurlFactory.php(102): GuzzleHttp\Handler\CurlFactory::finishError(对象(GuzzleHttp\Handler\CurlHandler), 对象(GuzzleHttp\Handler\EasyHandle), 对象(GuzzleHttp\Handler\CurlFactory)) #2 D :\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler \EasyHandle), 对象(GuzzleHttp\Handler\CurlFactory)) #3 D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle 在 D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php 第 185 行
// URL = http://test.example.localhost/api/lang-sync
public static function test($url, $data) {
$client = new \GuzzleHttp\Client();
$res = $client->request('POST', $url, $data);
$response = $res->getBody();
if($res->getStatusCode() == 200)
{
print_r($res);
} else {
print_r($response);
}
}
在登台服务器上没问题。重新启动 xampp 没有帮助。
编辑:
test.example.localhost 已添加到主机文件中。
这是一个向 Laravel API 发送 http 请求的 wordpress 插件。
这个应用程序实际上是使用https://github.com/hyn/multi-tenant。用于多站点集成
解决方案
上面写着:
无法解析主机:
test.example.localhost
打开C:\Windows\System32\Drivers\etc\hosts
并添加以下条目:
127.0.0.1 test.example.localhost
以便知道主机名。
推荐阅读
- python - Python/Q#:未找到模块错误,.qs 文件位于同一目录中
- java - Jira 弹出消息
- php - Ajax POST 与 mysqli 数据库查询
- azure-ad-graph-api - Microsoft Graph API:为具有应用程序权限的多租户应用程序获取 ErrorAccessDenied
- makefile - 在 AOSP 中使用 soong build Android.bp 时找不到头文件
- excel - 将单元格复制到另一个工作表
- reactjs - 这是 React 组件的正确用法吗?
- java - OpenJFX 14 TextField NodeOrientation RIGHT_TO_LEFT 无法通过 Windows 10 上的键盘移动光标
- sql - 以 15 秒为间隔聚合(组)时间 // Microsoft SQL Server 2019
- javascript - 如何正确重置 Vue Composition Api 的反应值