感谢您观看此问题。我在 GCloud 中使用 grpc 作为后端,在前端使用 flutter,但无法通信。因为我想设置 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)
我搜索了谷歌和堆栈溢出,但没有找到解决此问题的有用信息。如果您有此类问题的经验,请帮助我或给我一些信息。非常感谢。