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("失败"); }); } }