当我尝试使用没有 ssl 的 grpc-web 时,它工作正常。我的方法是这样的
final channel = GrpcWebClientChannel.xhr(Uri.parse('http://192.168.43.130:8080'));
final client = GreeterClient(channel);
但是当我尝试用 ssl 实现它时,它会抛出一个错误。错误是这样的。
Error: gRPC Error (code: 2, codeName: UNKNOWN, message: HTTP request completed without a status (potential CORS issue), details: null, rawResponse: , trailers:
{})
at Object.throw_ [as throw] (http://localhost:38485/dart_sdk.js:5063:11)
at Object.validateHttpStatusAndContentType (http://localhost:38485/packages/grpc/src/shared/status.dart.lib.js:449:17)
at xhr_transport.XhrTransportStream.new.[_validateResponseState] (http://localhost:38485/packages/grpc/src/client/transport/xhr_transport.dart.lib.js:88:16)
at xhr_transport.XhrTransportStream.new.[_onRequestDone] (http://localhost:38485/packages/grpc/src/client/transport/xhr_transport.dart.lib.js:111:67)
at http://localhost:38485/packages/grpc/src/client/transport/xhr_transport.dart.lib.js:157:31
at Object._checkAndCall (http://localhost:38485/dart_sdk.js:5270:16)
at Object.dcall (http://localhost:38485/dart_sdk.js:5275:17)
at XMLHttpRequest.<anonymous> (http://localhost:38485/dart_sdk.js:108843:100)
这一次,我的做法是
final channel = GrpcWebClientChannel.xhr(Uri.parse('https://192.168.43.130:8080'));
final client = GreeterClient(channel);
使用 ssl ,我在envoy.yaml
文件中添加了以下行。
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
alpn_protocols: h2
validation_context:
trusted_ca:
filename: cert.pem
tls_certificates:
- certificate_chain:
filename: cert.pem
private_key:
filename: key.pem
笔记:- I am using self signed certificate using mkcert.