BufferedMediaTypeFormatter HttpContent does not contain all headers sent to Request

In my OWA Self Host Web Api project, I'm trying to create custom MediaTypeFormatterone that inherits from BufferedMediaTypeFormatter. But the problem is that the object HttpContentpassed in ReadFromStream(..)does not contain all the headers sent in the request.

How do you access all the headers that were sent in the request (I know this because I made the request), or access the source HttpRequestMessagein the method ReadFromStream(..)?

This seam will be the main mistake, and I can’t figure out why all the headers are Requestnot provided.

+4
source share
1 answer

, ASP.NET Request , .

, , , GetPerRequestFormatterInstance:

HTTP- ASP.NET WebAPI MediaTypeFormatter?

, , :

IEnumerable<string> headerValues = request.Headers.GetValues("MyHeaderFieldName");
var id = headerValues.FirstOrDefault();

:

Request.InputStream.Position = 0;
var input = new StreamReader(Request.InputStream).ReadToEnd();
-1

Source: https://habr.com/ru/post/1614581/


All Articles