| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 886 人关注过本帖
标题:ASP.NET的实时天气及24小时天气预报
只看楼主 加入收藏
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
结帖率:80.91%
收藏
 问题点数:0 回复次数:1 
ASP.NET的实时天气及24小时天气预报
网上找到的 运行一下 点击第一个按钮出现
StartIndex 不能小于 0。
参数名: startIndex
点击第二个按钮出现远程服务器返回错误: (404) 未找到。
由于从没做过所以也不明白是怎么回事 希望大家给看一下



 
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.

<html xmlns="http://www. >
<head runat="server">
<title>GetWeather</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.

</head>
<body>
    <form id="form1" runat="server">
    <FONT face="宋体"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <P> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label id="lblWeather" runat="server">Weather</asp:Label></P> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <P> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Button id="btnGet" runat="server" Text="Get Weather" OnClick="btnGet_Click2"></asp:Button></P> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <P> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label id="Weather2" runat="server">24小时天气</asp:Label></P> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <P> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Button id="btnGet2" runat="server" Text="天气预报"></asp:Button></P> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>
    </form>
</body>
</html>






using System;
using System.Collections;
using
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using
using
public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: This call is required by the Web Form Designer.
        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.btnGet.Click += new System.EventHandler(this.btnGet_Click);
        this.btnGet2.Click += new System.EventHandler(this.btnGet2_Click);
        this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion



    protected void btnGet_Click(object sender, EventArgs e)
    {
        WebRequest wreq = WebRequest.Create("http://weather.);

        HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();

        string HTML = "";
        Stream s = wresp.GetResponseStream();

        StreamReader objReader = new StreamReader(s);

        string sLine = "";
        int i = 0;

        while (sLine != null)
        {
            i++;
            sLine = objReader.ReadLine();
            if (sLine != null)
                HTML += sLine;
        }

        String temp = "";
        int  start, stop;

        start = HTML.IndexOf("<!-- CURCON-->", 0, HTML.Length);

        stop = HTML.IndexOf("<!-- END CURCON-->", 0, HTML.Length);
        

        temp = HTML.Substring(start, stop-start);
        start = temp.IndexOf("<b>");
        stop = temp.IndexOf("</b>");

        string degree = temp.Substring(start+3, stop-start-3);

        start = temp.IndexOf("<img");
        stop = temp.IndexOf("</td>", start);

        string img = temp.Substring(start, stop-start);
        lblWeather.Text = degree + "<br>" + img;


    }

    protected void btnGet2_Click(object sender, EventArgs e)
    {
         WebRequest wreq=WebRequest.Create("http://cn.weather.);
                 
            HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse();
                     
            string HTML ="";
            Stream s=wresp.GetResponseStream();
                 
            StreamReader objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
     

            string sLine = "";
            int i = 0;

            while (sLine!=null)
            {
                i++;
                sLine = objReader.ReadLine();
                if (sLine!=null)
                    HTML += sLine;
            }
                 
            String temp= "";
            int start,stop;
                             
            start = HTML.IndexOf("<table border=0 cellpadding=2 cellspacing=1 bgcolor=9999cc width=\"85%\">",0,HTML.Length);

            stop = HTML.IndexOf("</table>",start)+8;
            

            temp = HTML.Substring(start, stop - start);
            Weather2.Text = temp;         
         


    }
 
}
搜索更多相关主题的帖子: 天气预报 NET 实时 ASP 
2008-09-15 11:30
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
要实现这个一般都是通过气象台提供的webservices来实现的……
你的这个例子我也不知道是不是应用了没有,所以也看不出来什么愿意,我有一个完整的例子,如果需要联系我……
2008-09-15 12:46
快速回复:ASP.NET的实时天气及24小时天气预报
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029617 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved