Why cant I see the Content-Encoding: gzip response in my c# HttpClient response header? -
i'm making simple c# program establish if server side compression available/enabled on various servers. request code below.
using (var client = new httpclient()) { client.timeout = new timespan(0, 0, 5); client.defaultrequestheaders.add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); client.defaultrequestheaders.add("user-agent", "mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/48.0.2564.97 safari/537.36"); client.defaultrequestheaders.add("accept-encoding", "gzip, deflate, sdch, br"); var httpclientresponse = client.getasync(websiteurl).result; string header = httpclientresponse.headers.getvalues("content-encoding").first(); }
i can see watching request in fiddler compression enabled request can't seem extract information response headers in code.
these full headers request , response.
get https://www.dobbies.com/ http/1.1 accept: text/html, application/xhtml+xml, application/xml; q=0.9, image/webp, */*; q=0.8 user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/48.0.2564.97 safari/537.36 accept-encoding: gzip, deflate, sdch, br host: www.dobbies.com http/1.1 200 ok cache-control: private content-type: text/html; charset=utf-8 content-encoding: gzip vary: accept-encoding server: set-cookie: asp.net_sessionid=hx1rb34ottgfritgt3rciql4; path=/; secure; httponly x-frame-options: sameorigin x-content-type-options: nosniff strict-transport-security: max-age=31536000 x-xss-protection: 1; mode=block date: fri, 07 apr 2017 08:06:17 gmt content-length: 16836
this when use httpclientresponse.headers
{ vary: accept-encoding x-frame-options: sameorigin x-content-type-options: nosniff strict-transport-security: max-age=31536000 x-xss-protection: 1; mode=block cache-control: private date: fri, 07 apr 2017 08:06:17 gmt set-cookie: asp.net_sessionid=hx1rb34ottgfritgt3rciql4; path=/; secure; httponly server: }
as can see header of content-encoding: gzip missing in response.
why header missing? along others. give me headers!
found problem.
the httpresponsemessage returned httpclient methods has 2 header properties:
httpresponsemessage.headers httpresponseheaders generic response headers
httpresponsemessage.content.headers httpcontentheaders content-specific headers content-type
Comments
Post a Comment