Flutter 如何在Flatter的gRPC客户端中设置TLS选项?

Flutter 如何在Flatter的gRPC客户端中设置TLS选项?,flutter,security,ssl,grpc,pem,Flutter,Security,Ssl,Grpc,Pem,感谢收看这个问题。我在GCloud中使用grpc作为后端,在前端使用flatter,但无法通信。因为我想设置tls连接,但是如果无法读取.pem文件。这是我的客户端初始化代码 final trustedRoot = new File('cert.pem').readAsBytesSync(); final channelCredentials = new ChannelCredentials.secure(certificates: trustedRoot);

感谢收看这个问题。我在GCloud中使用grpc作为后端,在前端使用flatter,但无法通信。因为我想设置tls连接,但是如果无法读取.pem文件。这是我的客户端初始化代码

    final trustedRoot = new File('cert.pem').readAsBytesSync();
    final channelCredentials =
        new ChannelCredentials.secure(certificates: trustedRoot);
    final channel = ClientChannel(
      '101.164.19.23',
      port: 8080,
      options: ChannelOptions(
        credentials: channelCredentials,
      ),
    );

    return testClient(channel);
并报告错误:

Error: Unsupported operation: _Namespace
    at Object.throw_ [as throw] (http://localhost:61406/dart_sdk.js:5333:11)
    at Function.get _namespace [as _namespace] (http://localhost:61406/dart_sdk.js:55298:17)
    at io._File.new.openSync (http://localhost:61406/dart_sdk.js:53257:45)
    at io._File.new.readAsBytesSync (http://localhost:61406/dart_sdk.js:53320:25)
    at web_stub.WebStub.new.getGrpcStub (http://localhost:61406/packages/piaodi/client/base_stub.dart.lib.js:46:52)
    at new grpc_client_singleton.GrpcClientSingleton._internal (http://localhost:61406/packages/piaodi/client/grpc_client_singleton.dart.lib.js:42:28)
    at get _singleton (http://localhost:61406/packages/piaodi/client/grpc_client_singleton.dart.lib.js:53:14)
    at Function.desc.get [as _singleton] (http://localhost:61406/dart_sdk.js:5869:17)
    at Function.new (http://localhost:61406/packages/piaodi/client/grpc_client_singleton.dart.lib.js:36:56)
    at lottery_page._LotteryPageState.new._joinLottery (http://localhost:61406/packages/piaodi/ui/lottery_page.dart.lib.js:464:71)
    at _joinLottery.next (<anonymous>)
    at runBody (http://localhost:61406/dart_sdk.js:39051:34)
    at Object._async [as async] (http://localhost:61406/dart_sdk.js:39082:7)
    at lottery_page._LotteryPageState.new.[_joinLottery] (http://localhost:61406/packages/piaodi/ui/lottery_page.dart.lib.js:462:20)
    at lottery_page._LotteryPageState.new.<anonymous> (http://localhost:61406/packages/piaodi/ui/lottery_page.dart.lib.js:454:72)
    at Generator.next (<anonymous>)
    at runBody (http://localhost:61406/dart_sdk.js:39051:34)
    at Object._async [as async] (http://localhost:61406/dart_sdk.js:39082:7)
    at http://localhost:61406/packages/piaodi/ui/lottery_page.dart.lib.js:453:1088
    at ink_well._InkResponseState.new.[_handleTap] (http://localhost:61406/packages/flutter/src/material/icon_button.dart.lib.js:50511:42)
错误:不支持的操作:\u命名空间
at Object.throw uu[as throw](http://localhost:61406/dart_sdk.js:5333:11)
在Function.get_namespace[作为_namespace](http://localhost:61406/dart_sdk.js:55298:17)
在io上。\u File.new.openSync(http://localhost:61406/dart_sdk.js:53257:45)
在io上。\u File.new.readAsBytesSync(http://localhost:61406/dart_sdk.js:53320:25)
在web_stub.WebStub.new.getGrpcStub(http://localhost:61406/packages/piaodi/client/base_stub.dart.lib.js:46:52)
在新的grpc_客户_singleton.GrpcClientSingleton.\u内部(http://localhost:61406/packages/piaodi/client/grpc_client_singleton.dart.lib.js:42:28)
在get_singleton(http://localhost:61406/packages/piaodi/client/grpc_client_singleton.dart.lib.js:53:14)
在Function.desc.get[as_singleton](http://localhost:61406/dart_sdk.js:5869:17)
在Function.new(http://localhost:61406/packages/piaodi/client/grpc_client_singleton.dart.lib.js:36:56)
在彩票页面。彩票页面状态。新。彩票(http://localhost:61406/packages/piaodi/ui/lottery_page.dart.lib.js:464:71)
在_.next()
在runBody(http://localhost:61406/dart_sdk.js:39051:34)
at对象。\u异步[作为异步](http://localhost:61406/dart_sdk.js:39082:7)
在彩票页面。彩票页面状态。新。[[u联合彩票](http://localhost:61406/packages/piaodi/ui/lottery_page.dart.lib.js:462:20)
在彩票页面。彩票页面state.new。(http://localhost:61406/packages/piaodi/ui/lottery_page.dart.lib.js:454:72)
在Generator.next()处
在runBody(http://localhost:61406/dart_sdk.js:39051:34)
at对象。\u异步[作为异步](http://localhost:61406/dart_sdk.js:39082:7)
在http://localhost:61406/packages/piaodi/ui/lottery_page.dart.lib.js:453:1088
在ink_well._InkResponse Estate.新建。[[u handleTap](http://localhost:61406/packages/flutter/src/material/icon_button.dart.lib.js:50511:42)
我搜索了google和stack overflow,但没有找到解决此问题的有用信息。如果你有这方面的经验,请帮助我或给我一些信息。非常感谢