encoding - C#/Why does Get html returns random junk characters? -
encoding - C#/Why does Get html returns random junk characters? -
i have ex: link
this code:
const string nick = "alex"; const string log = "http://demonscity.combats.com/zayavka.pl?logs="; foreach (datetime cd in daterange) { string str = log + string.format("{0:mm_dd_yy}", cd.date) + "&filter=" + nick; string htmlcode = wc.downloadstring(str); }
returns something...."‹\b\0\0\0\0\0\0я•xysЫЦ~зЇёѕ™d)bг.тbҐ$ЪrЖ’<2Уn&сh@р ’„\f\0j–—_Фџђ§¤нt¦г6ќѕУЄђ0’iqtТґcµо№x(jі-Щ/Ђі|g?`yҐ¶ц"
other links works fine. think problem codepage, how can prepare it? or it's server problem?
the issue response gzip-compressed (response has content-encoding: gzip
header). need first decompress it, you'll able read it:
public class stackoverflow_6660689 { public static void test() { webclient wc = new webclient(); encoding encoding = encoding.getencoding("windows-1251"); byte[] info = wc.downloaddata("http://demonscity.combats.com/zayavka.pl?logs=08_07_11&filter=alex"); gzipstream gzip = new gzipstream(new memorystream(data), compressionmode.decompress); memorystream decompressed = new memorystream(); gzip.copyto(decompressed); string str = encoding.getstring(decompressed.getbuffer(), 0, (int)decompressed.length); console.writeline(str); } }
c# encoding webclient downloadstring
Comments
Post a Comment