How to use HttpClient to fetch remote file and save in directory inside app?


#1
$fileUrl = 'https://example.com/file.xml.gz';
$http = new Client();
$response = $http->get($fileUrl,[], ['type' => 'xml', 'timeout' => 600]);
$xml = $response->xml;
....

How to use HttpClient to fetch remote file and save in directory inside app?


#2
    $fileUrl = 'https://example.com/file.xml.gz';
    $http = new Client();
    $response = $http->get($fileUrl);
    file_put_content('file.xml.gz', $response->body);

You can get XML after unzip.
BR.


#3

Thanks, but in this case that not work. I use Guzzle Client and now all woking.