WP7上HttpWebRequest的用法

1.创建request对象

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://www.cnblogs.com/"));
request.BeginGetResponse(ResponseCallback,request);

2.

 void ResponseCallback(IAsyncResult result)
        {
            try
            { 
            HttpWebRequest request = (HttpWebRequest)(result.AsyncState);

            StreamReader read = new StreamReader(request.EndGetResponse(result).GetResponseStream());
            string data = read.ReadToEnd();
            string dt = data.Substring(0,1024);
            Dispatcher.BeginInvoke(() => {
                MessageBox.Show(dt);
            });
            }
            catch 
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("失败");
                });
            }
        }

 

posted @ 2013-02-04 14:34  NSDefaultRunLoopMode  阅读(190)  评论(0编辑  收藏  举报