【问题标题】:Why is the HTTP request works fine in Tinker but not in the app in Laravel 7?为什么 HTTP 请求在 Tinker 中可以正常工作,但在 Laravel 7 的应用程序中却不行?
【发布时间】:2020-08-18 06:47:28
【问题描述】:

我正在尝试将执行POST 请求的文件上传到API。因此,当我在 Tinker 中对其进行测试时,它工作正常,上传文件大约需要 5 秒,但是当我使用 Postman 测试我自己的端点时,我收到了这个错误:

"message": "最大执行时间超过 60 秒"。

不知道为什么它在 Tinker 上可以正常工作,但在应用程序中却不行。

我的请求如下所示:

$response = Http::attach('file', file_get_contents(asset('storage/' . $attachment->type . '/' . $attachment->name)), $attachment->name)
        ->post('https://api-example.com/endpoint', 
            [
                'uid' => env('HANDWRYTTEN_UID'),
                'type' => 'cover'
            ]);
        return $response->json();

我已经清除了缓存和这样的配置

php artisan cache:clear

php artisan config:clear

非常感谢任何帮助!非常感谢!

【问题讨论】:

  • 是您的服务器或 API 抛出的 "message": "Maximum execution time of 60 seconds exceeded".?..
  • 是服务器抛出的
  • 是的,但是哪一个,你的还是 api 的?
  • 大声笑我的本地主机,而不是 API 的
  • 你测试的是同一个文件吗?

标签: php laravel api http tinker


【解决方案1】:

出于某种原因,我尝试更改发送file_get_contents() 的方式,我使用storage_path() 而不是asset(),它成功了!所以也许文件路径有错误,但我没有收到任何错误。现在已经解决了。谢谢!

【讨论】:

    猜你喜欢
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 2012-08-13
    • 2017-03-12
    相关资源
    最近更新 更多