Symfony 6-本地主机的连接被拒绝



我使用docker(来自symfony docs-https://github.com/dunglas/symfony-docker)在symfony 6中,我收到了:

Failed to connect to localhost port 443 after 0 ms: Connection refused for "https://localhost/products".

这个地址在浏览器中返回带有产品的json。

这是控制器:

<?php
namespace AppController;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyComponentHttpClientHttpClient;
use SymfonyComponentHttpFoundationJsonResponse;
class ApiController extends AbstractController
{   
#[Route('/apire', name: 'api')]
public function fetchGitHubInformation()
{
$client = HttpClient::create();
$response = $client->request('GET', 'https://localhost/products');

$content = $response->getContent();
$content = $response->toArray();

return new JsonResponse($content);
}
}

这是来自caddy docker容器的netstat:

/srv/app # netstat -tulpn | grep LISTEN
tcp        0      0 127.0.0.11:45991        0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:2019          0.0.0.0:*               LISTEN      1/caddy
tcp        0      0 :::443                  :::*                    LISTEN      1/caddy
tcp        0      0 :::80                   :::*                    LISTEN      1/caddy

问题出在哪里?

解决方案来自这里-https://www.youtube.com/watch?v=1cDXJq_RyNc

当我更改为http://caddy/products-一切正常。

我刚刚将IP地址从localhost(:port)更改为我的windows IP地址192.168.x.x(:port),它成功了!

如果您有端口,请将(:端口(替换为您的端口。例如:http://192.168.x.x:8080

如何获取您的IP地址;

1 . Open cmd
2 . ipconfig
3 . Get the address from IPv4 Address.

相关内容

  • 没有找到相关文章

最新更新