加载完整的网站WinRT

时间:2012-11-26 14:37:36

标签: windows-runtime httpclient

我想用HttpClient加载Kepler引用页面,如下所示:

string resourceAddress = _url;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, resourceAddress);
            HttpClient httpClient = new HttpClient();
            // Do not buffer the response:
            HttpResponseMessage response = new HttpResponseMessage();
            response = await httpClient.SendAsync(request,
                 HttpCompletionOption.ResponseContentRead);



            using (Stream responseStream = await response.Content.ReadAsStreamAsync())
            {
                int read = 0;
                byte[] responseBytes = new byte[(Int32)responseStream.Length];
                do
                {
                    read = await responseStream.ReadAsync(responseBytes, 0, responseBytes.Length);
                } while (read != 0);
            }

但我认为,页面不会被加载完整,就像没有所有图像和iframe等...

1 个答案:

答案 0 :(得分:0)

下载第一段html很少能够为你提供页面的所有元素,即使你解析它并包含所有链接的图像等。还有css和javascript会带来新的内容当您在浏览器中打开页面并自己获取所有这些时,将进入视图将类似于实现您自己的浏览器。您最好的选择是在WebView控件中加载一次页面并让它缓存其内容或使用WebView并扫描DOM以尝试获取所有元素。您还可以编写一个Web服务,为您下载页面并向您提供整个包...假设页面不需要身份验证。