[英]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.