Is there any inbuilt umbraco API which support access to outside data?
Hi All, I would like tp know if there any inbuilt umbraco API which allows to access content of a page of a website built on non-umbraco platform. Or in other words is there any umbraco API by using which we can pull content of page of a website.Thanks in advanceViren
No however lets say you have a static html page at some site eg. http://mysite/some.html you could create a razor macro that uses .net httpclient to pull down that page and write out its content in your site.
WebResponse res = req.GetResponse(); StreamReader sr = new StreamReader(res.GetResponseStream()); string html = sr.ReadToEnd();
If you wanted to then further process that html and say only get content with a certain div then you could load it into a library like htmlagility pack and xpath out what you need
HtmlDocument doc = new HtmlDocument();
doc.Load(html);
foreach(HtmlNode div in doc.DocumentElement.SelectNodes("//div"])
{
//do some stuff with div.
}
An even simpler, one-line approach I use for fetching external HTTP content:
string html = new System.Net.WebClient().DownloadString(whateverUrl);
Be sure to cache this result depending on how frequently the source data is updated. Keep in mind this is a synchronous action, so however long it takes to fetch that remote page will be added on top of the time required for your umbraco page to render.
If you were fetching resources from multiple pages at once, then it might be worthwhile to look into how to run multiple web requests asynchronously, so that this total time to fetch remote pages is only as long as the longest/slowest one.
Is there any inbuilt umbraco API which support access to outside data?
Hi All, I would like tp know if there any inbuilt umbraco API which allows to access content of a page of a website built on non-umbraco platform. Or in other words is there any umbraco API by using which we can pull content of page of a website.Thanks in advanceViren
Virendra,
No however lets say you have a static html page at some site eg. http://mysite/some.html you could create a razor macro that uses .net httpclient to pull down that page and write out its content in your site.
using System.Net;
using System.IO;
WebRequest req = WebRequest.Create("http://mysite/some.html");
WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string html = sr.ReadToEnd();
If you wanted to then further process that html and say only get content with a certain div then you could load it into a library like htmlagility pack and xpath out what you need
Regards
Ismail
An even simpler, one-line approach I use for fetching external HTTP content:
Be sure to cache this result depending on how frequently the source data is updated. Keep in mind this is a synchronous action, so however long it takes to fetch that remote page will be added on top of the time required for your umbraco page to render.
If you were fetching resources from multiple pages at once, then it might be worthwhile to look into how to run multiple web requests asynchronously, so that this total time to fetch remote pages is only as long as the longest/slowest one.
Best of luck to you!
is working on a reply...