日期:2014-05-17 浏览次数:20761 次
string line;
using (Stream st = wr.GetResponseStream())
{
StreamReader sr = new StreamReader(st);
while ((line = sr.ReadLine()) != null)
{
if (line.Contains("charset="))
{
string nowEncoding = GetCharset(line);
if (nowEncoding != "UTF-8")
{
sr = new StreamReader(st, Encoding.GetEncoding(nowEncoding));
content = sr.ReadToEnd();
}
else
{
content = sr.ReadToEnd();
}
}
}
}
var request = HttpWebRequest.Create("http://www.amazon.co.jp/");
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
Regex regex = new Regex(@"(?<=charset=)\w+");
var sr = new StreamReader(
stream,
Encoding.GetEncoding(regex.Match(response.ContentType).Value));
Console.WriteLine(sr.ReadToEnd());
}