php - cURL 错误 6 : Could not resolve host: test. example.localhost(参见 http ://curl. haxx.se/libcurl/c/libcurl-errors.html)

标签 php curl multi-tenant guzzlehttp

我试图 curl 到我的本地主机 laravel 站点。我正在使用 XAMPP 7.1 当我尝试重新连接此代码时,总是会出现错误(而不是 200 OK 响应)

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: test.example.localhost (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:185 Stack trace: #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)) #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), Object(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);

    }
 }

在登台服务器上没问题。
重新启动 xampp 没有帮助。

编辑:

test.example.localhost 已添加到主机文件中。

这是一个向 Laravel API 发送 http 请求的 wordpress 插件。

这个应用实际上是在使用 https://github.com/hyn/multi-tenant .用于多站点集成

最佳答案

它写道:

Could not resolve host: test.example.localhost



打开 C:\Windows\System32\Drivers\etc\hosts并添加此条目:
127.0.0.1 test.example.localhost

以便知道主机名。

关于php - cURL 错误 6 : Could not resolve host: test. example.localhost(参见 http ://curl. haxx.se/libcurl/c/libcurl-errors.html),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53942204/

相关文章:

php - laravel 更新功能不起作用

php - WordPress 获取条款和订单

php - 从客户端向服务器发送变量 | JSON 与 POST

PHP cURL 同时保存图像并获取 header 响应

c# - SignalR - Multi-Tenancy 依赖注入(inject)

spring - 在子上下文中覆盖父上下文中定义的 bean

PHP进程超时后不会终止

php - 使用php和mysql记录curl GET请求的结果

php - 如何为 get_headers PHP 函数设置用户代理

Django:如何让 setUpTestData 为所有测试运行一次?