简体   繁体   English

Symfony - Guzzle 请求:cURL 错误 6:无法解析主机

[英]Symfony - Guzzle request: cURL error 6: Could not resolve host

I have a symfony application with two controllers.我有一个带有两个控制器的 symfony 应用程序。 One of the controllers randomly return an element of an array, like this:其中一个控制器随机返回一个数组元素,如下所示:

$responses = array("foo", "bar", "baz");

return new JsonResponse($responses[array_rand($responses)]);

The other one has a form and if that form is valid and is submitted it should create a new guzzle client and display one of the array elements from the other controller:另一个有一个表单,如果该表单有效并被提交,它应该创建一个新的 guzzle 客户端并显示来自另一个控制器的数组元素之一:

...
if ($form->isSubmitted() && $form->isValid()) {
    $client = new Client([
        'base_uri' => 'foo.local',
    ]);
    $response = $client->request('GET', '/bar');

This results in a cURL error 6: Could not resolve host.这会导致cURL 错误 6:无法解析主机。

I do have nginx up and running and can access both controllers separately via their routes.我确实启动并运行了 nginx,并且可以通过它们的路由分别访问两个控制器。

I could not find any solutions, hope someone can help me out with some ideas on this.我找不到任何解决方案,希望有人能帮助我解决这个问题。

using protocol in the base uri solves the could not resolve host error在基本 uri 中使用协议解决了无法解析主机错误

'base_uri' => 'http://foo.local' instead of 'base_uri' => 'foo.local' in this case 'base_uri' => 'http://foo.local'而不是'base_uri' => 'foo.local'在这种情况下

Thans for the help @Matteo感谢@Matteo的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM