简体   繁体   English

为什么 HTTP 请求在 Tinker 中可以正常工作,但在 Laravel 7 的应用程序中却不行?

[英]Why is the HTTP request works fine in Tinker but not in the app in Laravel 7?

I'm trying to upload a file doing a POST request to an API .我正在尝试将执行POST请求的文件上传到API So when I test it in Tinker it works fine, it takes like 5 seconds to upload the file, but when I test my own endpoint using Postman I get this error:因此,当我在 Tinker 中对其进行测试时,它工作正常,上传文件大约需要 5 秒,但是当我使用Postman测试我自己的端点时,我收到此错误:

"message": "Maximum execution time of 60 seconds exceeded". "message": "最大执行时间超过 60 秒"。

Not sure why is it working on Tinker fine but not in the app.不知道为什么它在 Tinker 上运行良好,但在应用程序中却不行。

Here's how my request looks like:这是我的请求的样子:

$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();

I have cleared the cache and config like this我已经像这样清除了缓存和配置

php artisan cache:clear

and

php artisan config:clear

Any help is very much appreciated!很感谢任何形式的帮助! Thank you very much!非常感谢!

For some reason I tried to change the way to send file_get_contents() and I used storage_path() instead of asset() and it worked.出于某种原因,我试图改变发送file_get_contents()的方式,我使用storage_path()而不是asset()并且它有效。 So maybe there was an error with the file path but I wasn't getting any errors about that.因此,文件路径可能存在错误,但我没有收到任何错误。 It's now solved.现在已经解决了。 Thank you!谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么一个http发帖请求无法正常工作但在curl中可以正常工作 - why an http post request isn't working in guzzle but works fine in curl 在Laravel中,为什么在应用程序事件之前,Request :: segment()方法可以正常工作,而Route :: currentRouteName()却不能正常工作? - In Laravel, Why with the `before` application event, `Request::segment()` method works fine and `Route::currentRouteName()` does not? 为什么php ==不能在工匠修补匠laravel上使用 - why php == not working on artisan tinker laravel Ajax请求返回HTTP 503,但脚本运行正常 - Ajax request returns HTTP 503 but script works fine Laravel SQLSTATE[HY000] [2002] 连接被拒绝但修补程序工作 - Laravel SQLSTATE[HY000] [2002] Connection refused but tinker works 为什么Laravel“Console :: info()”不起作用,错误:“我的控制器中找不到”类'App \\ Http \\ Controllers \\ Console'? - Why Laravel “Console::info()” doesn't works, error: “Class 'App\Http\Controllers\Console' not found in MY CONTROLLER”? Laravel 具有来自修补程序的未定义常量 App\User - Laravel Has undefined contstant App\User from tinker 为什么相同的http请求在浏览器中有效,但从Android应用发送时却失败? - Why the same http request works in browser and fails when sent from my Android app? Laravel通过Http请求无响应(PHPUnit正常) - Laravel Unresponsive Via Http Request (PHPUnit Works Ok) 为什么HTTP在公共文件夹的laravel和.htaccess文件中请求POST和PUT,这在本地计算机上很好用,而在实时服务器上却不起作用? - Why HTTP request POST and PUT in laravel and .htaccess file of public folder, that works great in local machine, not working in live server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM