Skip to main content
Home Forums Silverlight Programming Programming with .NET - General How can I get a remote page's HTML source?
4 replies. Latest Post by swildermuth on December 2, 2008.
(0)
dawmail333
Member
0 points
4 Posts
12-01-2008 7:07 AM |
I'm after the source of a remote webpage, but every method I've tried to use has just timed out or not worked.
How, using Silverlight 2.0, can I get the source of a remote (cross-domain) webpage? I need to sift through it to gather some information.
Thanks in advance.
swildermuth
Star
8320 points
1,546 Posts
12-01-2008 8:08 AM |
You can only request the page if the other domain supoorts a cross domain access file (crossdomain.xml or the silverlight equivalent). Else, it won't return any HTML.
Priyamjm
234 points
32 Posts
12-01-2008 11:12 AM |
swildermuth is correct.
Refer:
HTTP Communication and Security with Silverlight
http://msdn.microsoft.com/en-us/library/cc838250(VS.95).aspx
Downloading Content on Demand
http://msdn.microsoft.com/en-us/library/cc189021(VS.95).aspx
EX:
void foo(string str_url) { WebClient oWebClient = new WebClient(); oWebClient.OpenReadCompleted += new OpenReadCompletedEventHandler(oWebClient_OpenReadCompleted); oWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(oWebClient_DownloadProgressChanged); oWebClient.OpenReadAsync(new Uri(str_url), str_url); } void oWebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { string strProgress = e.ProgressPercentage.ToString() + "%"; } void oWebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { if (null == e.Result) { //Some Error. } else if (e.Cancelled) { //Cancelled } else { Stream oStream = e.Result as Stream; //Use oStream //Your code here } }
//Hope this will help you
12-02-2008 1:27 AM |
Seems like a bit of a no-brainer to me, there are so many ways around that.
Unless of course, it's because it is done client side and therefore can get information from pages they are authenticated on... Is that what they call XSS? I'm not sure.
12-02-2008 2:23 AM |
You could do it server side (not using Silverlight) pretty easily, its the cross-site (XSS) support that isn't allowed.