强制 guzzle 下载 zip 文件
forcing guzzle to download the zip files
需要帮助下载 json 响应 zip 文件。
我正在使用来自远程服务器的 guzzle json 响应,其中 returns 文件名和修改日期是我的。我想将所有这些 zip 文件下载到我本地服务器的存储文件夹中..
所以它会像这样工作
远程服务器给出 json 个响应文件名
我获取文件名并创建我的 link 并强制 guzzle 将这些文件下载到我的本地服务器。
这是我的代码
ini_set('max_execution_time', '0');
$url = "https://feeds.example.com/zips/publisher/";
try
{
$client = new GuzzleHttp\Client();
$res = $client->request('GET', $url, [
'auth' => ['username', 'password'],
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json'
],
]);
$responses = json_decode($res->getBody()->getContents());
foreach ($responses->incrementalFeed as $feed)
{
$downloadLink = $url . $feed->name;
$client->get($downloadLink, ['auth' => ['username', 'password']]);
Storage::put($feed->name, $downloadLink);
}
}
catch (ClientException $e) {
echo $e->getMessage();
}
它将所有 zip 文件下载到我的存储文件夹,但所有文件都是 1kb,空的..但是在远程网站中,这些文件从 10mb 到 600mbs
我做错了什么?
你没有下载任何东西。
您需要再次使用 guzzle 下载文件
例如
$response = $client->get($downloadLink);
Storage::put($feed->name, $response->getBody());
需要帮助下载 json 响应 zip 文件。 我正在使用来自远程服务器的 guzzle json 响应,其中 returns 文件名和修改日期是我的。我想将所有这些 zip 文件下载到我本地服务器的存储文件夹中..
所以它会像这样工作 远程服务器给出 json 个响应文件名 我获取文件名并创建我的 link 并强制 guzzle 将这些文件下载到我的本地服务器。
这是我的代码
ini_set('max_execution_time', '0');
$url = "https://feeds.example.com/zips/publisher/";
try
{
$client = new GuzzleHttp\Client();
$res = $client->request('GET', $url, [
'auth' => ['username', 'password'],
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json'
],
]);
$responses = json_decode($res->getBody()->getContents());
foreach ($responses->incrementalFeed as $feed)
{
$downloadLink = $url . $feed->name;
$client->get($downloadLink, ['auth' => ['username', 'password']]);
Storage::put($feed->name, $downloadLink);
}
}
catch (ClientException $e) {
echo $e->getMessage();
}
它将所有 zip 文件下载到我的存储文件夹,但所有文件都是 1kb,空的..但是在远程网站中,这些文件从 10mb 到 600mbs
我做错了什么?
你没有下载任何东西。 您需要再次使用 guzzle 下载文件
例如
$response = $client->get($downloadLink);
Storage::put($feed->name, $response->getBody());