Windows phone 7 使用C访问网站
我正在尝试为windows phone 7制作一个应用程序。该应用程序将基本上从我们在工作中使用的网站上检索信息,然后将检索到的信息重新排列到metro风格的UI中。老实说,我不知道从哪里开始(即如何检索信息)。我应该使用webclient类吗?httpwebrequest类?还是别的什么 所有的想法都被采纳了 以下是: 更新:- 好吧,要么我很笨,要么我写的代码有问题,我弄不明白。我使用的代码与您编写的代码相同,但我仍然收到一个错误,即System.Net.WebRequest中没有代理的定义:这是我的代码工作版本:-Windows phone 7 使用C访问网站,windows-phone-7,c#-4.0,Windows Phone 7,C# 4.0,我正在尝试为windows phone 7制作一个应用程序。该应用程序将基本上从我们在工作中使用的网站上检索信息,然后将检索到的信息重新排列到metro风格的UI中。老实说,我不知道从哪里开始(即如何检索信息)。我应该使用webclient类吗?httpwebrequest类?还是别的什么 所有的想法都被采纳了 以下是: 更新:- 好吧,要么我很笨,要么我写的代码有问题,我弄不明白。我使用的代码与您编写的代码相同,但我仍然收到一个错误,即System.Net.WebRequest中没有代理的定义
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
string url = "https://medinet.se/*****/schema/ibsef";
WebRequest request = WebRequest.Create(url);
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallBack), request);
}
private void ReadWebRequestCallBack(IAsyncResult callbackResult)
{
try
{
WebRequest myRequest = (WebRequest)callbackResult.AsyncState;
WebResponse myResponse = (WebResponse)myRequest.EndGetResponse(callbackResult);
using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
{
string results = httpwebStreamReader.ReadToEnd();
Dispatcher.BeginInvoke(() => parsertextBlock.Text = results);
}
myResponse.Close();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
Dispatcher.BeginInvoke(() => parsertextBlock.Text = ex.ToString());
}
}
但是如果我添加request.Proxy=null!!我得到一个错误,System.Net.WebRequest中没有代理的定义。老实说,我开始对这件事生气了
你的
/Omar这个过程称为ScreenSrape,我建议您使用Html Agility Pack。制作一个web服务,从您的网站检索信息并重新排列为适当的格式。通过电话使用web服务并显示数据 使用WebRequest和WebResponse 提示:将WebRequest.Proxy属性设置为null,因为我发现这样会更快 更新:有关WebRequest代理属性的详细信息 在WebRequest对象上设置Proxy=null以避免初始延迟,这样请求就不会启动自动检测代理,我发现这样更快
WebRequest req = WebRequest.Create("yourURL");
req.Proxy = null;
它位于System.Net命名空间中,因此使用System.Net放一个using语句;或
问候。谢谢你的回答,真的很有帮助;。我唯一不能做的就是WebRequest.Proxy,因为我找不到它:你知道silverlight和wp7是否可以使用这个属性吗?更新了这个问题。知道为什么会这样吗?
System.Net.WebRequest req = WebRequest.Create("yourURL");
req.Proxy = null;