HTTP GET

bhalpin
Member Posts: 309
Hi.
This question really has two parts:
The simple question is how to get a page from the web into a variable. I know it's through the use of an Automation variable, but which one and what method(s)? (I've been beating my head against a lot of walls 'cuz that's the best way to learn ... but it hurts now.)
The bigger question is this: I'm not an MS environment guro, I see all kinds of cool looking Automation classes through NAV, and I'm sorta comfortable with COM concepts in a differernt context/environment, but, what reference(s) would I use as a guide to what the classes do (for me in NAV particularly)?
Thank's in advance
This question really has two parts:
The simple question is how to get a page from the web into a variable. I know it's through the use of an Automation variable, but which one and what method(s)? (I've been beating my head against a lot of walls 'cuz that's the best way to learn ... but it hurts now.)
The bigger question is this: I'm not an MS environment guro, I see all kinds of cool looking Automation classes through NAV, and I'm sorta comfortable with COM concepts in a differernt context/environment, but, what reference(s) would I use as a guide to what the classes do (for me in NAV particularly)?
Thank's in advance
0
Comments
-
You can e.g. use "'Microsoft XML, v3.0'.XMLHTTP" if you want to read XML file and the code will be something as:
IF ISCLEAR(XMLDOMhttp) THEN CREATE(XMLDOMhttp); XMLDOMhttp.open('GET', MyURL, TRUE); YIELD; XMLDOMhttp.send(); IF ISCLEAR(XMLDOMDocument) THEN CREATE(XMLDOMDocument); XMLDOMDocument := XMLDOMhttp.responseXML(); ...
Or you can use automation "'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest" with the Open and WaitForResponse functions to get the data (but there will be some limitation what you can do with the result I think).0 -
Hi Kamil.
Thanks - I'm almost there - but not getting any usable data. Here's what I've got:Name DataType Length Subtype XMLDOMhttp Automation 'Microsoft XML, v3.0'.XMLHTTP XMLDOMDocument Automation 'Microsoft XML, v3.0'.DOMDocument XMLNode Automation 'Microsoft XML, v3.0'.IXMLDOMNode URL Text 128 XMLData Text 256 XMLDOMMgmt Codeunit BizTalk XML DOM Management URL := 'http://www.mibuso.com'; IF ISCLEAR(XMLDOMhttp) THEN CREATE(XMLDOMhttp); XMLDOMhttp.open('GET',URL,TRUE); YIELD; XMLDOMhttp.send(); IF ISCLEAR(XMLDOMDocument) THEN CREATE(XMLDOMDocument); XMLDOMDocument := XMLDOMhttp.responseXML(); // This doesn't work, XMLData is alway's empty XMLData := XMLDOMDocument.text; // I tried this, but still XMLData is alway's empty IF XMLDOMMgmt.FindNode(XMLDOMDocument,'/html/head/title',XMLNode) THEN XMLData := XMLNode.text;
I've got to be missing something really simple. Can you spot it?
Thanks (big time) in advance.0 -
Hyperlink('MyURL');
still makes me happy0 -
Thanks.
HyperLink opens IE on the URL, but I want the contents of the page in a C/AL variable so I can parse values from it.
Bob0 -
Have you check if there are datas in the xml? And the node exist?
Store the xml as file on hdd and take a look intoDo you make it right, it works too!0 -
bhalpin wrote:Thanks.
HyperLink opens IE on the URL, but I want the contents of the page in a C/AL variable so I can parse values from it.
Bob0 -
Have you check if there are datas in the xml? And the node exist?
Well, in the example I posted, I am using a URL I know exists (www.mibuso.com). Also, I would think that the line XMLData := XMLDOMDocument.text; would return the entire page, regardless of what nodes may or may not exist. But XMLData is alway's empty, no matter what URL I try.0 -
Yikes.
All I want to do is get the contents of a web page into a variable and I've been at it the whole day now. Here's the latest dead-end:Name DataType Subtype Length WinHttpReq Automation 'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest VHttpData Variant HttpData Text 1024 Type Text 30 URL := 'http://www.mibuso.com'; IF ISCLEAR(WinHttpReq) THEN CREATE(WinHttpReq); WinHttpReq.Open('GET',URL,FALSE); WinHttpReq.Send; IF NOT WinHttpReq.WaitForResponse() THEN ERROR('Timed out'); // Alway's displays '200' and 'OK' MESSAGE( 'Status: '+FORMAT(WinHttpReq.Status())+'\'+ 'StatusText: '+WinHttpReq.StatusText() ); // Get the response body into a variant VHttpData := WinHttpReq.ResponseBody; // Now, what is it? Type := 'Unknown'; IF VHttpData.ISRECORD THEN Type :='RECORD'; IF VHttpData.ISFILE THEN Type :='FILE'; IF VHttpData.ISACTION THEN Type :='ACTION'; IF VHttpData.ISCODEUNIT THEN Type :='CODEUNIT'; IF VHttpData.ISAUTOMATION THEN Type :='AUTOMATION'; IF VHttpData.ISBOOLEAN THEN Type :='BOOLEAN'; IF VHttpData.ISOPTION THEN Type :='OPTION'; IF VHttpData.ISINTEGER THEN Type :='INTEGER'; IF VHttpData.ISDECIMAL THEN Type :='DECIMAL'; IF VHttpData.ISCHAR THEN Type :='CHAR'; IF VHttpData.ISTEXT THEN Type :='TEXT'; IF VHttpData.ISCODE THEN Type :='CODE'; IF VHttpData.ISDATE THEN Type :='DATE'; IF VHttpData.ISTIME THEN Type :='TIME'; IF VHttpData.ISBINARY THEN Type :='BINARY'; IF VHttpData.ISDATEFORMULA THEN Type :='DATEFORMULA'; IF VHttpData.ISTRANSACTIONTYPE THEN Type :='TRANSACTIONTYPE'; IF VHttpData.ISINSTREAM THEN Type :='INSTREAM'; IF VHttpData.ISOUTSTREAM THEN Type :='OUTSTREAM'; MESSAGE('Type is '+Type);
You guessed it, the type is 'Unknown'.
SURELY this can't be that hard! ](*,)0 -
please use 'Microsoft HTML Object Library'.HTMLXMLHttpRequest automation0
-
Ok, here's the attempt:
Name DataType Subtype Length HTMLXMLHttpRequest Automation 'Microsoft HTML Object Library'.HTMLXMLHttpRequest URL Text 128 URL := 'http://www.mibuso.com'; IF ISCLEAR(HTMLXMLHttpRequest) THEN CREATE(HTMLXMLHttpRequest); HTMLXMLHttpRequest.open('GET',URL,FALSE); HTMLXMLHttpRequest.send;
Here's the result:Could not create an instance of the OLE control or automation server identified by GUID={3050F1C5-98B5-11CF-BB82-00AA00BDCE0B} 4.0:{3051040B-98B5-11CF-BB82-00AA00BDCE0B}:'Microsoft HTML Object Library'.HTMLXMLHttpRequest.
](*,) #-o0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions