string url = "http://www.time.ac.cn/stime.asp";
HttpClient helper = new HttpClient();
Func<Task<string>> datehtmlfun = async () => await helper.GetStringAsync(url);
Task<string> datehtml = datehtmlfun();
string html = datehtml.Result;
网站是gb2312的编码,直接调用GetStringAsync用的估计是默认的UTF-8编码
这个有什么办法吗?
流的形式读出来,设置解码为gb2312
string result = "";
string url = "http://www.time.ac.cn/stime.asp";
HttpClient httpclient= new HttpClient();
var response = httpclient.GetAsync(url).Result;
if (response.IsSuccessStatusCode)
{
Stream myResponseStream = response.Content.ReadAsStreamAsync().Result;
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("GBK"));
result = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
}
return result;
Nice