SmartPhone手机上查看QQ天气预报
日期:2007年12月15日 作者: 查看:[大字体 中字体 小字体]-
}
#endregion
#region GetPageString 获取QQ的天气服务
//private string xx="";
[WebMethod(Description="天气预报")]
public string GetPageString(string cityName)
{
string url=@"http://appnews.qq.com/cgi-bin/news_qq_search";
return GetPage(url,cityName);
}private static string GetPage(string url,string cityName)
{
HttpWebResponse res = null;
string strResult = "";
try
{
string postData = "city=" + HttpUtility.UrlEncode(cityName,System.Text.Encoding.GetEncoding("GB2312"));
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.KeepAlive = true;
req.ContentType = "application/x-www-form-urlencoded";
StringBuilder UrlEncoded = new StringBuilder();
byte[] SomeBytes = Encoding.ASCII.GetBytes(postData);
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();//获得流内容
res = (HttpWebResponse)req.GetResponse();
System.IO.Stream s=res.GetResponseStream();
StreamReader reader = new StreamReader(s,System.Text.Encoding.Default);
strResult=reader.ReadToEnd();
}
catch(Exception e)
{
strResult = e.ToString();
}
finally
{
if ( res != null )
{
res.Close();
}
}strResult=strResult.Remove(0,strResult.IndexOf("●"));
if( cityName != "北京" )
{
strResult=strResult.Remove(strResult.IndexOf("北京"),strResult.Length-strResult.IndexOf("北京"));
}
else
{
strResult=strResult.Remove(strResult.LastIndexOf("北京"),strResult.Length-strResult.LastIndexOf("北京"));
}strResult=strResult.Trim();
while(strResult.IndexOf(@"<") != -1)
{
strResult=strResult.Remove(strResult.IndexOf(@"<"),strResult.IndexOf(@">")-strResult.IndexOf(@"<")+1);
}while(strResult.IndexOf(@" ") != -1)
{
strResult=strResult.Replace(" ","");
}
string x = Encoding.UTF8.GetString(new Byte[]{10});
string y = Encoding.UTF8.GetString(new Byte[]{9});while(strResult.IndexOf(x) != -1)
{
strResult=strResult.Replace(x,"");
}while(strResult.IndexOf(y) != -1)
{
strResult=strResult.Replace(y,"");
}
return strResult;
}#endregion
}
}记得将在Web.Config文件加入以下节点,使得WebService能被外部访问
<!-- WebService 获取的途径 -->
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="HttpPostLocalhost"/?
<add name="Documentation"/>
</protocols>
</webServices>
三、新建手机应用程序项目
1、新建一个智能设备应用程序,在主面板上拖放如图2所示的几个控件,其中timer是用来检查是否数据已经下载完毕的。

图1-新建智能设备应用程序

- 上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页
- 相关文章:
- 相关软件
·神气兔宝贝中文版 ·QQ空间人气精灵3.80 Beta4 ·[GBA]元气史莱姆:冲击的尾巴团 ·小鸡报天气QQ表情 ·桌面天气秀(XDeskWeather)v4.1 ·金庸群侠传2003之剑气碧烟横 ·电脑万能加锁专家 2006 世界气象日特别版 ·奇童梦乐-语气篇2006夏 ·信普天气预报v5.7 ·龙帝天气预报 V1.99 正式版 上一篇:QQ聊天避开木马病毒攻击的小技巧
- 特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作
- 者.文章版权归文章原始作者所有.对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转
- 载的文章有版权问题请联系编辑人员,我们尽快予以更正. 转载请注明来源:http://www.hackhome.com
精品推荐
热点TOP10
特别推荐
