简体   繁体   English

Xamarin forms 和 gRPC:服务器返回无效或无法识别的响应

[英]Xamarin forms and gRPC: The server returned an invalid or unrecognized response

I am trying to get a response from the gRPC service but I get the error that the server returned an invalid or unrecognized response when I make the call from a Xamarin application.我正在尝试从 gRPC 服务获取响应,但是当我从 Xamarin 应用程序进行调用时,我收到服务器返回无效或无法识别的响应的错误。 However, if I use a WPF client, that use the same gRPC client library than the Xamarin application, it works as exepected, I get the response from the service.但是,如果我使用 WPF 客户端,它使用与 Xamarin 应用程序相同的 gRPC 客户端库,它会按预期工作,我会从服务中获得响应。

The service code is this:服务代码是这样的:

            webBuilder.ConfigureKestrel(options =>
            {
                options.Listen(IPAddress.Any, 5001, listenOptions =>
                {
                    listenOptions.Protocols = HttpProtocols.Http2;
                    listenOptions.UseHttps("server.pfx", "1111");
                });
            });
            webBuilder.UseStartup<Startup>();

Client library:客户端库:

        HttpClientHandler miHandler = new HttpClientHandler();

        miHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

        GrpcChannelOptions misOpciones = new GrpcChannelOptions() { HttpHandler = miHandler };

        var miChannel = GrpcChannel.ForAddress("https://192.168.1.134:5001", misOpciones);

What I am doing wrong?我做错了什么? At first I thought it was because from android I couldn't use http, that I need https, but now I am using https.起初我以为是因为从android我不能使用http,我需要https,但现在我使用的是http,但现在我使用的是https,但现在我使用的是http,但现在我使用的是https。 It is true that I am ignoring any certificate from the server, could it be this the reason for that?确实,我忽略了来自服务器的任何证书,这可能是原因吗? But the error message it would be related with SSL or something like that, instead of telling that the response is not recognized.但是错误消息将与 SSL 或类似的东西有关,而不是告诉响应无法识别。

Thanks.谢谢。

EDIT: in the console aplication that hosts the service, I get this fail: HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint.编辑:在托管服务的控制台应用程序中,我失败了:HTTP/2 over TLS 未在仅 HTTP/2 的端点上协商。

You could try to use Grpc.Core or gRPC-Web as it is mentioned in the documentation .您可以尝试使用文档中提到的Grpc.CoregRPC-Web

Calling gRPC over HTTP/2 with Grpc.Net.Client is currently not supported on Xamarin. Xamarin 目前不支持使用 Grpc.Net.Client 通过 HTTP/2 调用 gRPC。 We are working to improve HTTP/2 support in a future Xamarin release.我们正在努力在未来的 Xamarin 版本中改进对 HTTP/2 的支持。 Grpc.Core and gRPC-Web are viable alternatives that work today. Grpc.Core 和 gRPC-Web 是当今可行的替代方案。

And you may refer to https://stackoverflow.com/a/60362990/10768653 .您可以参考https://stackoverflow.com/a/60362990/10768653

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 gRPC客户端 - &gt;服务器连接失败 - 服务器返回无效或无法识别的响应 - gRPC Client->Server connection failed - The server returned an invalid or unrecognized response HttpClient中“服务器返回无效或无法识别的响应”的含义 - Meaning of “The server returned an invalid or unrecognized response” in HttpClient C# HttpClient GetAsync 异常“服务器返回无效或无法识别的响应” - C# HttpClient GetAsync exception “The server returned an invalid or unrecognized response” 是什么原因导致HttpClient中出现“ WinHttpException:服务器返回了无效或无法识别的响应”? - What causes “WinHttpException: The server returned an invalid or unrecognized response” in HttpClient? 服务器返回无效或不完整的 HTTP 响应 - The server returned an invalid or incomplete HTTP response 在Xamarin Forms构建中导致“无法识别的选择器发送到类”错误的原因是什么? - What causes “unrecognized selector sent to class” error on Xamarin Forms build? 语法错误,命令无法识别。 服务器响应为 &#39;&#39; - Syntax error, command unrecognized. The server response was '' Xamarin.Forms gRPC 启动 gRPC 调用时出错:连接上的流意外结束 - Xamarin.Forms gRPC Error starting gRPC call: unexpected end of stream on Connection 如何使用C#(Xamarin Forms)在应用程序周围保存和访问服务器响应? - How to save and access server response around the app with C# (Xamarin Forms)? Xamarin.Forms应用程序上的无效强制转换异常 - Invalid Cast Exception on Xamarin.Forms app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM