Windows Phone开发之WebClient的用法

来源:互联网 发布:淘宝新手怎么推广 编辑:程序博客网 时间:2024/06/06 03:42

说明:
就个人使用来说,WebClient的使用方法和访问WebService有很多相似之处。不同点是Webservice需要建立本地Web引用,但是WebClient就不需要。而且对于访问的URL,WebClient更容易更改。
比如访问如下:

string url = "http://www.youdao.com/smartresult-xml/search.s?jsFlag=true&type=mobile&q=" + Phone.Text.Trim().ToString();            WebClient client = new WebClient();            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);            client.DownloadStringAsync(new Uri(url, UriKind.Absolute));           void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)        {}

代码说明:
url为根据电话号码查询归属地的一个web接口。
因为电话号码是动态变化的,所以使用WebClient更方便一些。

此处访问电话号码归属地查询的接口,找到了一些,但是都是gbk编码格式,而wp不能识别gbk编码,所以中文会有乱码现象。

电话号码归属地查询:

http://www.hujuntao.com/archives/phone-numbers-attribution-to-api-interface.html

原创粉丝点击