HttpClientService.php 548 B

12345678910111213141516171819202122
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Facades\Http;
  4. class HttpClientService
  5. {
  6. /**
  7. * 创建带标准头的HTTP客户端
  8. */
  9. public static function make(string $timeout = '10'): \Illuminate\Http\Client\PendingRequest
  10. {
  11. return Http::timeout((int) $timeout)
  12. ->withHeaders([
  13. 'Accept' => 'application/json',
  14. 'Content-Type' => 'application/json',
  15. 'User-Agent' => 'Laravel/' . (app()->version()),
  16. ])
  17. ->retry(2, 200);
  18. }
  19. }