Http contentLength与实际文件大小不同

时间:2017-09-22 06:50:17

标签: c# content-length

获取HttpResponse消息contentLength as:

var contentLength = response.Content.Headers.ContentLength;
Console.WriteLine(contentLength);

获取XML文件长度:

FileInfo f = new FileInfo(fileName);
long filesize = f.Length;

现在打印尺寸时,它给我一个3970,其他3968。 我想比较两种尺寸,但由于这种差异,我没有做到。任何帮助?

1 个答案:

答案 0 :(得分:0)

检查流的前2个字节与文件。 UTF-16有一个2字节的BOM,可能是:

http://www.opentag.com/xfaq_enc.htm#enc_default

First bytes        Encoding assumed
-----------------------------------------
EF BB BF           UTF-8
FE FF              UTF-16 (big-endian)
FF FE              UTF-16 (little-endian)
00 00 FE FF        UTF-32 (big-endian)
FF FE 00 00        UTF-32 (little-endian)
None of the above  UTF-8