读取 grpc 的 dot net core 中间件中的请求正文

Sha*_*bir 5 .net-core grpc-dotnet

我有一个单一服务,它使用 dot net core 3.1 托管 API 控制器和 GRPC。\n我有需要同时适用于两者(API 和 GRPC)的中间件,并且我需要读取其中的请求正文。\n我尝试过下面的方法,它适用于 API 请求,但不适用于 grpc。当我读取流时,我在其中获取 grpc 请求负载的 unicode 字符,例如“\\0\\0\\0\\0\xef\xbf\xbd\\n\xef\xbf\xbd\\u0001”。

\n
httpContext.Request.EnableBuffering();\nvar reqVal = await new StreamReader(httpContext.Request.Body).ReadToEndAsync();\nhttpContext.Request.Body.Position = 0;\n
Run Code Online (Sandbox Code Playgroud)\n