Yve*_*aga 4 php curl multi-tenant guzzlehttp
我试图卷曲到我的本地主机 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(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2D :\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 in D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 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);
}
}
Run Code Online (Sandbox Code Playgroud)
在登台服务器上没问题。重新启动 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
Run Code Online (Sandbox Code Playgroud)
以便知道主机名。