【问题标题】:Bad hostname provided提供了错误的主机名
【发布时间】:2022-01-24 18:43:41
【问题描述】:

护照版本:^10.1

Laravel 版本:8.77.1

PHP 版本:8.0.9

数据库驱动和版本:mysql 8.0.27

我无法获得访问令牌。 当我通过 curl 手动调用它时,它会得到这个响应。

这个主机名是在 docker 容器内生成的

我正在测试 docker 容器的 192.168.224.6 ip,但它也不起作用


/var/www/html # curl --location --request POST 'http://docker-nginx/oauth/token' \
> --header 'Accept: application/json' \
> --form 'grant_type="password"' \
> --form 'client_id="4"' \
> --form 'client_secret="hZJ33buLLIe3ekqe1dv62tn6RkBFMp59fZjeBgPW"' \
> --form 'username="creatrre@gmail.org"' \
> --form 'password="creatrre@gmail.com"' \
> --form 'scope=""'
{
    "message": "Bad hostname provided.",
    "exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
    "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php",
    "line": 391,
    "trace": [
        {
            "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php",
            "line": 332,
            "function": "prepareException",
            "class": "Illuminate\\Foundation\\Exceptions\\Handler",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/app/Exceptions/Handler.php",
            "line": 97,
            "function": "render",
            "class": "Illuminate\\Foundation\\Exceptions\\Handler",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 51,
            "function": "render",
            "class": "App\\Exceptions\\Handler",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 172,
            "function": "handleException",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustHosts.php",
            "line": 48,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Http\\Middleware\\TrustHosts",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 103,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 142,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 111,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/var/www/html/releases/20211223205412/public/index.php",
            "line": 52,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        }
    ]
/var/www/html #


【问题讨论】:

  • 当控制器中有一些定义错误的函数时,我通常会发生这种情况,例如缺少大括号。
  • --form 'scope=""' 的右大括号似乎丢失了。
  • 可能@hup 指示的行末尾缺少反斜杠

标签: php laravel docker docker-compose laravel-passport


【解决方案1】:

如果护照不用前缀,最好使用

APP URL 代替 docker 容器名称 http://docker-nginx

http://docker-nginx/oauth/token 错误

env('APP_URL')/oauth/token 正确

【讨论】:

    猜你喜欢
    • 2019-04-30
    • 2015-03-02
    • 2021-12-31
    • 2010-09-17
    • 2022-01-10
    • 2016-03-26
    • 1970-01-01
    • 2021-09-10
    • 2014-03-15
    相关资源
    最近更新 更多