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

csga3l58  于 2023-08-06  发布在  其他
关注(0)|答案(2)|浏览(118)

我正在使用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 App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpFoundation\JsonResponse;

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


问题出在哪里?

dfddblmv

dfddblmv1#

解决方案来自这里-https://www.youtube.com/watch?v=1cDXJq_RyNc
当我切换到http://caddy/products-一切正常。

wydwbb8l

wydwbb8l2#

我只是改变了IP地址从localhost(:port)到我的Windows IP地址192.168.x.x(:port)和它的工作!
如果您有端口,请将(:port)替换为您的端口。例如:http://192.168.x.x:8080
如何获取您的IP地址;

相关问题