1

当我在本地开发环境中时,我无法将 Guzzle 与外部网站一起使用。我可以使用 Guzzle,而不会与我机器上的其他本地站点发生故障。

我目前无法在本地环境中将 Guzzle 与外部网站一起使用。

编码

我在本地 Laravel 应用程序中有以下测试路线:

Route::get('guzzle', function() {
$client = new GuzzleHttp\Client();
$response = $client->get("http://www.google.com");
dd($response);
});

响应

当我从本地环境执行此代码时,我收到以下错误:

cURL error 6: Couldn't resolve host 'www.google.com' (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

我可以在本地网站上使用 Guzzle。

编码

Route::get('guzzle', function() {
$client = new GuzzleHttp\Client();
$response = $client->get("http://test.dev");
dd($response);
});

响应

Response {#180 ▼
-reasonPhrase: "OK"
-statusCode: 200
-headers: array:7 [▶]
-headerLines: array:7 [▶]
-protocol: "1.1"
-stream: Stream {#171 ▶}
}

...我需要帮助。

我看了这么久,我需要一些新的想法。希望有人有想法或起点。

这是 Laravel 返回的完整错误消息。

ConnectException in CurlFactory.php line 186:
cURL error 6: Couldn't resolve host 'www.google.com' (see   http://curl.haxx.se/libcurl/c/libcurl-errors.html)
in CurlFactory.php line 186
at CurlFactory::createRejection(object(EasyHandle), array('errno' => '6', 'error' => 'Couldn't resolve host 'www.google.com'', 'url' => 'http://www.google.com/', 'content_type' => null, 'http_code' => '0', 'header_size' => '0', 'request_size' => '0', 'filetime' => '-1', 'ssl_verify_result' => '0', 'redirect_count' => '0', 'total_time' => '0', 'namelookup_time' => '0', 'connect_time' => '0', 'pretransfer_time' => '0', 'size_upload' => '0', 'size_download' => '0', 'speed_download' => '0', 'speed_upload' => '0', 'download_content_length' => '-1', 'upload_content_length' => '-1', 'starttransfer_time' => '0', 'redirect_time' => '0', 'redirect_url' => '', 'primary_ip' => '', 'certinfo' => array(), 'primary_port' => '0', 'local_ip' => '', 'local_port' => '0')) in CurlFactory.php line 150
at CurlFactory::finishError(object(CurlMultiHandler), object(EasyHandle),     object(CurlFactory)) in CurlFactory.php line 103
at CurlFactory::finish(object(CurlMultiHandler), object(EasyHandle), object(CurlFactory)) in CurlMultiHandler.php line 180
at CurlMultiHandler->processMessages() in CurlMultiHandler.php line 108
at CurlMultiHandler->tick() in CurlMultiHandler.php line 123
at CurlMultiHandler->execute(true) in Promise.php line 240
at Promise->invokeWaitFn() in Promise.php line 217
at Promise->waitIfPending() in Promise.php line 261
at Promise->invokeWaitList() in Promise.php line 219
at Promise->waitIfPending() in Promise.php line 62
at Promise->wait() in Client.php line 129
at Client->request('get', 'http://www.google.com/', array()) in Client.php line 87
at Client->__call('get', array('http://www.google.com/', array(), array('proxy' => 'http://10.0.1.2'))) in routes.php line 29
at Client->get('http://www.google.com/', array(), array('proxy' => 'http://10.0.1.2')) in routes.php line 29
at RouteServiceProvider->{closure}()
at call_user_func_array(object(Closure), array()) in Route.php line 155
at Route->runCallable(object(Request)) in Route.php line 130
at Route->run(object(Request)) in Router.php line 712
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 714
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 679
at Router->dispatchToRoute(object(Request)) in Router.php line 639
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
4

0 回答 0