我正在使用 Docker(来自 Symfony 文档 - 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
问题出在哪里?
https://[::1]/products
加载你的网站吗? - Álvaro González