如何从 WP7 中的服务器获取响应?
我正在尝试使用 WP7 上的 HttpWebRequest 类发送请求,但没有得到任何响应... 这是我的代码:
InitializeComponent();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
tbResponse.Text = reader.ReadToEnd();
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
Console.ReadLine();
此外,我使用此扩展:单击此处,但是我在Windows控制台应用程序上测试了它,没有任何问题,所以我认为问题是我对WP7不了解。
I'm trying to send a request with the HttpWebRequest class on WP7, but I don't get any response...
Here is my code:
InitializeComponent();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
tbResponse.Text = reader.ReadToEnd();
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
Console.ReadLine();
Moreover, I use this extension: click here, but I tested it on a Windows Console Application and there wasn't any problem, so I think the problem is that I don't know something about WP7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要像这样发出异步请求:
和响应处理程序:
这是我开发的一个帮助程序类,用于在开发 Windows Phone 7 应用程序期间处理我的 Web 请求需求:
http://www.manorey.net/mohblog/?p=17&preview=true
You need to make asynchronous requests like this:
and the response handler:
Here is a helper class I developed to handle my web request needs during development of windows phone 7 apps:
http://www.manorey.net/mohblog/?p=17&preview=true