解压缩的Web API响应
问题描述:
我压缩具有以下配置解压缩的Web API响应
<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" />
现在网络API响应时我消耗这一个双赢的形式应用,并尝试做follwoing
var rawData = await response.Content.ReadAsStringAsync();
var deserializedData = JsonConvert.DeserializeObject<Employees[]>(rawData).ToList();
它失败
var deserializedData = JsonConvert.DeserializeObject(r awData).ToList();
错误消息是
{"Unexpected character encountered while parsing value: . Path '', line 0, position 0."}
我想这是由于这样的事实内容gziped并没有被反序列化。任何人都可以提出解决方案这个本地工作细如本地IIS没有启用GZIP
答
您需要启用自动GZip压缩解压:
var handler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip };
var client = new HttpClient(handler);
非常感谢,这工作 – InTheWorldOfCodingApplications