如何将完整的 URL 作为端点添加到 GET 请求

How to add a full URL as an endpoint to a GET request

我正在尝试发出 GET 请求并添加一个完整的 url 变量,就像这样

     * @Route("/foobar/{url}", name="foobar", methods={"GET"})

然而,当我尝试在邮递员中调用它时

http://foo.bar.local/post/https://www.google.de/

我明白了

   No route found for "GET /foobar/https://www.google.de/"

但是如果我做任何其他事情,例如

1
www.google.de

我得到了正确的回应

我做错了什么?

您可以在路线注释上添加要求,例如:

/**
 * @Route("/url-test/{url}", name="url_test", methods={"GET"}, requirements={"url"=".+"})
 */
public function url_test($url)
{
    dump($url); // https://www.google.de/
}

并检查我使用 url : https://127.0.0.1:8000/url-test/https://www.google.de/

文档:https://symfony.com/doc/4.1/routing/slash_in_parameter.html