首页 > 解决方案 > 从 laravel 下载 Flutter 文件:HandshakeException: Handshake error in client

问题描述

我制作了一个颤振程序来从 laravel 下载 pdf 文件。按下载按钮时出现错误。

Exception has occurred.
HandshakeException (HandshakeException: Handshake error in client (OS Error: 
    CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354)))

这是我的下载功能:

Future<File> _downloadFile() async{
    final res = await Network().download("/letter/download/${surat.id_surat}");
    var bytes = await consolidateHttpClientResponseBytes(res);
    String dir = (await getApplicationDocumentsDirectory()).path;
    File file = new File('$dir/Surat_${surat.id_surat}');
    await file.writeAsBytes(bytes);
    return file;
  }

这就是 Network() 的功能

download(apiUrl) async{
    var fullUrl = "https://sub.domain.id/api" + apiUrl;
    await _getToken();
    return await http.get(
      fullUrl,
      headers: _setHeaders()
    );
  }

这是我的 Laravel 下载 pdf 文件的功能

public function download($id_surat){
        $fileName = $this->saveToPDF($id_surat);
        $file = public_path()."/surat/".$fileName;
        $headers = array('Content-Type: application/pdf',);
        return Response::download($file, $fileName, $headers);
    }

标签: laravelflutterlaravel-api

解决方案


推荐阅读