国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

webman如何通過(guò)url獲取文件流直接轉(zhuǎn)發(fā)給客戶(hù)端?

RainLee1990

問(wèn)題描述

根據(jù)url直接獲取文件流發(fā)送給客戶(hù)端,服務(wù)器本地不做存儲(chǔ),當(dāng)前參考文檔 http://www.wtbis.cn/doc/workerman/components/workerman-http-client.html 寫(xiě)的代碼文件時(shí)下載下來(lái)了但是報(bào)文件是損壞的打不開(kāi),一下是具體代碼

public function download(Request $request): \support\Response
{
    $url = $request->get('url');
    if (empty($url)) {
        return response_json(400, '參數(shù)不能為空');
    }
    $headers = get_headers($url, 1);

    if (!$headers || !str_contains($headers[0], '200')) {
        return response_json(400, 'URL不可訪問(wèn)', null, 403);
    }

    try {
        $connection = $request->connection;
        $http = new Client();
        $http->request($url, [
            'method' => 'GET',
            'progress' => function ($buffer) use ($connection) {
                $connection->send(new Chunk($buffer));
            },
            'success' => function ($response) use ($connection) {
                $connection->send(new Chunk('')); // 發(fā)送空的的chunk代表response結(jié)束
            },
        ]);
    } catch (\Throwable $e) {
        return response_json(500, $e->getMessage());
    }
    return response()->withHeaders([
        "Content-Type" => $headers['Content-Type'],
        "Transfer-Encoding" => "chunked",
    ]);
}
431 1 0
1個(gè)回答

不懂就問(wèn),為什么這個(gè)url不直接給前端下載

  • 大古 2025-04-28

    "Content-Type" => $headers['Content-Type'],

  • RainLee1990 2025-04-29

    因?yàn)橐谛〕绦蛴茫蛎嘈〕绦虻南螺d域名填寫(xiě)不全

  • 超高級(jí)的稻姬 2025-04-30

    你是否在搜索nginx代理,搜索nginx proxy_pass可以解決你的大部分問(wèn)題

??