当前位置:学会吧培训频道电脑知识学习网页制作移动WAP开发用C#读取sina天气预报到wap页面» 正文

用C#读取sina天气预报到wap页面

[08-08 00:46:21]   来源:http://www.xuehuiba.com  移动WAP开发   阅读:8806
概要: HttpWebRequest request; request = (HttpWebRequest)WebRequest.Create(strURL); request.Method="POST"; //Post请求方式 request.ContentType="application/x-www-form-urlencoded"; //内容类型 string paraUrlCoded = System.Web.HttpUtility.UrlEncode("city"); //参数经过URL编码 paraUrlCoded = paraUrlCoded + "=" + System.Web.HttpUtility.UrlEncode(city,
用C#读取sina天气预报到wap页面,标签:移动WAP开发教程,wap网站开发,http://www.xuehuiba.com
            HttpWebRequest request;
            request = (HttpWebRequest)WebRequest.Create(strURL);
            request.Method="POST"; //Post请求方式
            request.ContentType="application/x-www-form-urlencoded"; //内容类型
            string paraUrlCoded = System.Web.HttpUtility.UrlEncode("city");
            //参数经过URL编码
            paraUrlCoded = paraUrlCoded + "=" +
            System.Web.HttpUtility.UrlEncode(city,
            System.Text.Encoding.GetEncoding("GB2312"));
            byte[] payload;
            payload =
            System.Text.Encoding.GetEncoding("GB2312").GetBytes(paraUrlCoded);
            //将URL编码后的字符串转化为字节
            request.ContentLength = payload.Length; //设置请求的ContentLength
            Stream writer = request.GetRequestStream(); //获得请求流
            writer.Write(payload,0,payload.Length); //将请求参数写入流
            writer.Close(); //关闭请求流
            HttpWebResponse response;
            response = (HttpWebResponse)request.GetResponse(); //获得响应流
            Stream s;
            s = response.GetResponseStream();
            StreamReader objReader = new
            StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
            string HTML = "";
            string sLine = "";
            int i = 0;
            while (sLine!=null)
            ...{
            i++;
            sLine = objReader.ReadLine();
            if (sLine!=null)
            HTML += sLine;
            }
            HTML = HTML.Replace("<","<");
            HTML = HTML.Replace(">",">");
            int start,stop;
            start = HTML.IndexOf("<img
            src="http://image2.sina.com.cn/dy/weather/images/figure/",0,HTML.Length);
            stop = HTML.IndexOf("<td
            background=http://image2.sina.com.cn/dy/weather/images",start);
            temp = HTML.Substring(start, stop - start);
            }

上一页  [1] [2] [3] [4] [5] [6]  下一页


Tag:移动WAP开发移动WAP开发教程,wap网站开发电脑知识学习 - 网页制作 - 移动WAP开发
《用C#读取sina天气预报到wap页面》相关文章
Copyright 学会吧 All Right Reserved.
在线学习社区!--学会吧
1 2 3 4 5 6 7 7 8 9 10 11 12 13