5

I am having one single service that is hosing both API controllers and GRPC with dot net core 3.1. I have middlewares that need to work for both (API and GRPC) and I have a need to read Request Body in it. I tried the below approach, where it works fine for API requests, but its not working in case of grpc. When I read stream I get unicode chars in it for grpc request payloads like this "\0\0\0\0�\n�\u0001".

httpContext.Request.EnableBuffering();
var reqVal = await new StreamReader(httpContext.Request.Body).ReadToEndAsync();
httpContext.Request.Body.Position = 0;
Shabbir
  • 51
  • 1
  • You can use grpc Interceptor instead of Middleware – Artem Illarionov Dec 29 '21 at 12:08
  • @ArtemIllarionov : I ended up doing same thing, its just that for API Controller had to keep the middleware and for grpc had to keep interceptor. And somehow put the logic in common class. – Shabbir Dec 30 '21 at 13:03

0 Answers0