Load Web Documents

Loading web documents is easy using Microsoft .NET Framework in Dynamics AX. All necessary classes are implemented in System.IO Namespace and ready to use in Dynamics AX. For example reading the HTML document from Axaptapedia.com can be done in this way:

System.Net.WebRequest request = System.Net.WebRequest::Create("http://www.axaptapedia.com"); System.Net.WebResponse response; System.IO.StreamReader reader; System.IO.Stream stream; System.String line; response = request.GetResponse; stream = response.GetResponseStream; reader = new System.IO.StreamReader(stream); line = reader.ReadLine; while(line != null) {   info(line); line = reader.ReadLine; } reader.Close;

or shorter (using WebClient class)

public static void TEST_DownloadString (Args _args) {   System.Net.WebClient webClient = new System.Net.WebClient; ;   info(webClient.DownloadString('http://axaptapedia.com')); }

Example using proxy and credentials (via masia) System.Net.WebClient        webClient = new System.Net.WebClient; System.Net.WebProxy         webProxy  = new System.Net.WebProxy("proxy"); str                         s;   ; webProxy.set_UseDefaultCredentials(true); webClient.set_Proxy(webProxy); webClient.set_Credentials(new System.Net.NetworkCredential("user", "password"));

s = webClient.DownloadString("url")

Loading XML document
While XML is the default industry standard for data exchange, it is simple to load published XML documents. News Feeds are published as XML documents that are interpreted by a browser or mail client like outlook to provide a convenient user interface. To handle XML documents add the System.Xml namespace at the AOT. static void Job8(Args _args) {   XmlDocument doc = new XMLDocument; XmlNodeList nodeList; XMLElement element; doc.load(@'http://www.axaptapedia.com/index.php?title=Special:Recentchanges&feed=rss'); nodeList = doc.selectNodes(@'//item'); for(element = nodeList.nextNode; element; element = nodeList.nextNode) {       info(element.getNamedElement('title').text); } }