How to set content encoding in HttpResponseMessage

I want to set Content-Encoding to HttpResponseMessage, and I cannot learn how to do this for my whole life. Given this action WebApi

public HttpResponseMessage Get() { byte[] tile = GetTile(); var result = new HttpResponseMessage(HttpStatusCode.OK) {Content = new ByteArrayContent(tile)}; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-protobuf"); return result; } 

How to set Content-Encoding in gzip header?

  result.Content.Headers.ContentEncoding 

read-only.

+5
source share
2 answers

The ContentEncoding property is an instance of ICollection . This provides additional and clear content management techniques.

+6
source

Do not distract richzilla from the answer, which, of course, is completely correct and answered my question. Seeing how it gets a few votes and visits, there must be other people making the same mistake as me, so it’s worth saying that the complete answer to my problem was

 result.Content.Headers.ContentEncoding.Add("gzip"); 
+1
source

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


All Articles