简体   繁体   English

C# gRPC localhost - 启动 gRPC 调用时出错:不知道这样的主机

[英]C# gRPC localhost - Error starting gRPC call: No such host is known

I'm trying to get Microsoft's gRPC "Greeter" application to work on my business laptop, but I keep getting the following exception when invoking the gRPC call:我正在尝试让 Microsoft 的 gRPC“Greeter”应用程序在我的商务笔记本电脑上运行,但在调用 gRPC 调用时我不断收到以下异常:

Grpc.Core.RpcException: 'Status(StatusCode=Internal, Detail="Error starting gRPC call: No such host is known.")'

This is the documentation from Microsoft, which I followed. 这是我遵循的 Microsoft 的文档。 The exact code I'm running comes from Microsoft's samples and can be found on their github here .我正在运行的确切代码来自 Microsoft 的示例,可以在此处的 github 上找到

It literally boils down to starting the most basic gRPC server and then invoking the call via它实际上归结为启动最基本的 gRPC 服务器,然后通过

using var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client =  new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });

The call to SayHelloAsync is the one that throws the exception.对 SayHelloAsync 的调用是引发异常的调用。 The exact same code on my home machine works fine.我家用机器上完全相同的代码可以正常工作。 I've already checked my /etc/hosts file for weird entries, but nothing.我已经检查了我的 /etc/hosts 文件中是否有奇怪的条目,但什么也没有。 I've also tried changing https://localhost:5001 to https://[::1]:5001 and https://127.0.0.1:5001 , same exception, which I find incredibly weird.我还尝试将https://localhost:5001更改为https://[::1]:5001https://127.0.0.1:5001 .

I've also already tried http via AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);我也已经通过AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); and calling the http endpoint, same exception.并调用 http 端点,同样的例外。

I figured it out.我想到了。 As expected it was a problem with the networking setup of my work laptop.正如预期的那样,这是我的工作笔记本电脑的网络设置问题。

I had the HTTP_PROXY and HTTPS_PROXY environment variables set.我设置了 HTTP_PROXY 和 HTTPS_PROXY 环境变量。 These were picked up by the underlying HttpClient and tried routing the requests through the proxy.这些被底层 HttpClient 拾取并尝试通过代理路由请求。 Removing the HTTP_PROXY and HTTPS_PROXY environment variables fixed the problem.删除 HTTP_PROXY 和 HTTPS_PROXY 环境变量解决了这个问题。 Alternatively setting the NO_PROXY environment variable to localhost,127.0.0.1,::1 also fixed the problem.或者将 NO_PROXY 环境变量设置为localhost,127.0.0.1,::1也解决了这个问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM