gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 04:33:56 25 4
gpt4 key购买 nike

我正在使用 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。

这是 Controller :

  <?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://www.youtube.com/watch?v=1cDXJq_RyNc

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

关于Symfony 6 - 本地主机的连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71278828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com