Windows Phone 获取服务器源代码 [英] Windows phone get server source code

查看:20
本文介绍了Windows Phone 获取服务器源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取网站的源代码.在 Windows 应用程序中,一个简单的 http 请求就足够了.然而,在Windows Phone 中,它要复杂得多.我在谷歌上搜索了很多,并没有给出明确的答案.这是我尝试过但没有取得很大成功的方法.

I am trying to get the source code of a site. In windows application a simple http request would be enough. However in windows phone it is a lot more complicated. I searched a lot on google and didn't come with a clear answer. This is what I tried but without big success.

public static sReturn = "";

private string _InetGetSourceCode(string sUrl)
{
   _InetReadEx(sUrl);
   return sReturn;
}

private void _InetReadEx(string sUrl)
{
   WebClient client = new WebClient();

   client.DownloadStringCompleted += new    
   DownloadStringCompletedEventHandler(DownloadStringCallback2);
   client.DownloadStringAsync(new Uri(sUrl));
}

private static void DownloadStringCallback2(Object sender,DownloadStringCompletedEventArgs e)
{
   if (!e.Cancelled && e.Error == null)
   {
      sReturn = e.Result;
   }
}

我在这里做错了什么?

推荐答案

问题是您立即返回 sReturn,但下载要到将来的某个时间才能完成.所以sReturn在你返回的时候仍然是空字符串的默认值.

The problem is that you return sReturn immediately, but the download won't complete until some time in the future. So sReturn still has the default value of the empty string at the time you return it.

您可以下载此示例,其中包含执行以下操作的代码正是您想要使用 HttpClient 便携式库执行的操作.

You can download this sample which includes code for doing exactly what you want to do using the HttpClient portable library.

这篇关于Windows Phone 获取服务器源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆