winforms - Decompressing Web Api response -


i compressing web api responses following config

<system.webserver> <httpcompression directory="%systemdrive%\inetpub\temp\iis temporary compressed files">   <scheme name="gzip" dll="%windir%\system32\inetsrv\gzip.dll" />   <dynamictypes>     <add mimetype="text/*" enabled="true" />     <add mimetype="application/*" enabled="true" />     <add mimetype="*/*" enabled="false" />   </dynamictypes>   <statictypes>     <add mimetype="text/*" enabled="true" />     <add mimetype="application/*" enabled="true" />     <add mimetype="*/*" enabled="false" />   </statictypes> </httpcompression> <urlcompression dostaticcompression="true" dodynamiccompression="true" /> 

now when consume in win form applications , try follwoing

var rawdata = await response.content.readasstringasync();                    var deserializeddata = jsonconvert.deserializeobject<employees[]>(rawdata).tolist(); 

it fails on

var deserializeddata = jsonconvert.deserializeobject(rawdata).tolist();

the error message

{"unexpected character encountered while parsing value: . path '', line 0, position 0."} 

i guess due fact content gziped , not being deserialized. can suggest solution ? works locally fine local iis not gzip enabled

you need enable automatic gzip decompression:

var handler = new httpclienthandler { automaticdecompression = decompressionmethods.gzip }; var client = new httpclient(handler); 

Comments