webform中我做了个登陆页面,登录框旁边显示的是新浪新闻,代码如下
/// <summary>
/// 获取新浪新闻
/// </summary>
public string getUrlContent()
{
WebResponse result = null;
string newsText = "";
try
{
//获取新闻的网页源代码并设备编辑格式为“GB2312”
WebRequest req = WebRequest.Create(@"http://news.sina.com.cn/");
if (!CMMUtil.IsNullOrEmpty(req))
{
result = req.GetResponse(); Stream receiveStream = result.GetResponseStream();
StreamReader read = new StreamReader(receiveStream, Encoding.GetEncoding("GB2312"));
string strAll = read.ReadToEnd();
//如果获取到则读取
if (!CMMUtil.IsNullOrEmpty(strAll))
{
//设置起始标记
string startText = "<ul class=\"c_l14s_01\" id=\"sh_news_gn\">";
//找到起始标记的位置
int start = strAll.IndexOf(startText);
//获取从起始标记开始后面的所有内容
newsText = strAll.Substring(start);
//找到起始标记匹配的每一个结束标记
int end = newsText.IndexOf(@"</ul>") + 5;
//获取从起始标记到结束标记之间的内容
newsText = newsText.Substring(0, end);
}
}
}
catch (Exception)
{
newsText="请检查网络连接!";
}
return newsText; } 网速好的话,登录页面挺快;但是网速慢的话,导致真个页面加载都慢,如何实现,登录框等页面元素都显示出来,新闻才开始加载,不影响用户登陆。急~~在线等
/// <summary>
/// 获取新浪新闻
/// </summary>
public string getUrlContent()
{
WebResponse result = null;
string newsText = "";
try
{
//获取新闻的网页源代码并设备编辑格式为“GB2312”
WebRequest req = WebRequest.Create(@"http://news.sina.com.cn/");
if (!CMMUtil.IsNullOrEmpty(req))
{
result = req.GetResponse(); Stream receiveStream = result.GetResponseStream();
StreamReader read = new StreamReader(receiveStream, Encoding.GetEncoding("GB2312"));
string strAll = read.ReadToEnd();
//如果获取到则读取
if (!CMMUtil.IsNullOrEmpty(strAll))
{
//设置起始标记
string startText = "<ul class=\"c_l14s_01\" id=\"sh_news_gn\">";
//找到起始标记的位置
int start = strAll.IndexOf(startText);
//获取从起始标记开始后面的所有内容
newsText = strAll.Substring(start);
//找到起始标记匹配的每一个结束标记
int end = newsText.IndexOf(@"</ul>") + 5;
//获取从起始标记到结束标记之间的内容
newsText = newsText.Substring(0, end);
}
}
}
catch (Exception)
{
newsText="请检查网络连接!";
}
return newsText; } 网速好的话,登录页面挺快;但是网速慢的话,导致真个页面加载都慢,如何实现,登录框等页面元素都显示出来,新闻才开始加载,不影响用户登陆。急~~在线等
jquery 异步