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

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

问题描述

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

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天全站免登陆