C/Side & Automation server Microsoft WinHTTP Services

bhalpin
Member Posts: 309
Hi.
I'm experimenting with the Automation class 'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest'. It looks to me like I can use this to reach out and grab web content.
So far though, I haven't come up with much. The following code is my 'hacking-to-date':
When I run this, I get three odd characters in the MESSAGE window.
If I change the code to use a plain Text variable to store the respone in, I get the error "This data type is not supported by C/Side."
I'm having fun - but not getting very far.
Has anyone used this automation server (and can maybe point out where I'm being a total idiot), or know of any working examples anywhere?
Thanks in advance.
Bob
I'm experimenting with the Automation class 'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest'. It looks to me like I can use this to reach out and grab web content.
So far though, I haven't come up with much. The following code is my 'hacking-to-date':
Vars: WinHTTPRequest Type: Automation Automation server: Microsoft WinHTTP Services, version 5.1 Class: WinHttpRequest RText Type: BigText CREATE(WinHTTPRequest); WinHTTPRequest.Open('GET','http://www.mibuso.com',FALSE); WinHTTPRequest.Send; IF WinHTTPRequest. WaitForResponse(5000) THEN BEGIN CLEAR(RText); RText.ADDTEXT(WinHTTPRequest.ResponseBody()); MESSAGE(FORMAT(RText)); END ELSE MESSAGE('No Response');
When I run this, I get three odd characters in the MESSAGE window.
If I change the code to use a plain Text variable to store the respone in, I get the error "This data type is not supported by C/Side."
I'm having fun - but not getting very far.
Has anyone used this automation server (and can maybe point out where I'm being a total idiot), or know of any working examples anywhere?
Thanks in advance.
Bob
0
Comments
-
Hello,
What is it you are trying to achieve with WinHTTP, download content? Check -> Download content with NAV.Met vriendelijke groet, best regards,
Rvduuren0 -
Hi.
Thank's for that link - that look exactly like what I'm after.
The background is I want to download currency echange rate information from a given URL. I started a thread about this earlier and reciived an excellent link to the download section for an XML-based solution.
I'll probably go with this idea though - it's simpler and required fewer objects.
Bob0 -
To download an XML file from a website you can do this for example with this:
Name DataType Subtype Length URL Text 250 XMLHTTP Automation 'Microsoft XML, v4.0'.XMLHTTP40 XMLDoc Automation 'Microsoft XML, v4.0'.DOMDocument40 ---------------------------- OnPush() Name DataType Subtype Length XMLFile File XMLPort XMLport YourDesignedXMLPort Stream InStream DownloadXMLFile(Filename); IF XMLFile.OPEN(Filename) THEN BEGIN XMLFile.CREATEINSTREAM(Stream); XMLPort.SETSOURCE(Stream); IF NOT XMLPort.IMPORT THEN error('Could not import the file :-( '); end else error('No file to open'); ----------------------------- DownloadXMLFile(VAR Filename : Text[30]) IF ISCLEAR(XMLHTTP) THEN IF NOT CREATE(XMLHTTP) THEN ERROR(Text000); URL:= HEREYOURURLTOTHEXML; XMLHTTP.open('GET',URL,FALSE); XMLHTTP.send(); IF (XMLHTTP.status = 200) THEN BEGIN IF ISCLEAR(XMLDoc) THEN IF NOT CREATE(XMLDoc) THEN ERROR(Text000); XMLDoc.async:=FALSE; XMLDoc.load(XMLHTTP.responseBody); IF RemoveNamespace(XMLDoc,XMLDoc) THEN BEGIN Filename´:= ENVIRON('TEMP') + '\' + 'Filename.xml'; XMLDoc.save(Filename); END; CLEAR(XMLDoc); END ELSE ERROR('Can't find URL'); CLEAR(XMLHTTP); ----------------------- RemoveNamespace(XMLSourceDocument : Automation "'Microsoft XML, v4.0'.DOMDocument40";VAR XMLDestinationDocument : Automation "'Microsof Name DataType Subtype Length TempTable Record Item OutStreamStylesheet OutStream InStreamStylesheet InStream XMLStyleSheet Automation 'Microsoft XML, v4.0'.DOMDocument40 //here we remove not needed Namespaces TempTable.Picture.CREATEOUTSTREAM(OutStreamStylesheet); TempTable.Picture.CREATEINSTREAM(InStreamStylesheet); WITH OutStreamStylesheet DO BEGIN WRITETEXT('<?xml version="1.0" encoding="UTF-8"?>'); WRITETEXT('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'); WRITETEXT('<xsl:output method="xml" encoding="UTF-8" />'); WRITETEXT('<xsl:template match="/">'); WRITETEXT('<xsl:copy>'); WRITETEXT('<xsl:apply-templates />'); WRITETEXT('</xsl:copy>'); WRITETEXT('</xsl:template>'); WRITETEXT('<xsl:template match="*">'); WRITETEXT('<xsl:element name="{local-name()}">'); WRITETEXT('<xsl:apply-templates select="@* | node()" />'); WRITETEXT('</xsl:element>'); WRITETEXT('</xsl:template>'); WRITETEXT('<xsl:template match="@*">'); WRITETEXT('<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>'); WRITETEXT('</xsl:template>'); WRITETEXT('<xsl:template match="text() | processing-instruction() | comment()">'); WRITETEXT('<xsl:copy />'); WRITETEXT('</xsl:template>'); WRITETEXT('</xsl:stylesheet>'); END; IF ISCLEAR(XMLStyleSheet) THEN IF NOT CREATE(XMLStyleSheet) THEN EXIT(FALSE); IF NOT XMLStyleSheet.load(InStreamStylesheet) THEN EXIT(FALSE); IF ISCLEAR(XMLDestinationDocument) THEN IF NOT CREATE(XMLDestinationDocument) THEN EXIT(FALSE); XMLSourceDocument.transformNodeToObject(XMLStyleSheet,XMLDestinationDocument); EXIT(TRUE); ---------------------
So with this little example you can download a XML file from a specific url and import this file with a XMLPort (also you can use the XMLDom)
RegardsDo you make it right, it works too!0 -
Yikes! Never ask a question here unless you're ready to accept *LOTS* of help!
This is all great stuff people - thanks!
I was just reading the article at the link below the previous post here came in. This looks really good:
http://blogs.msdn.com/nav_developer/archive/2008/03/31/sample-of-how-to-read-a-simple-xml-document-using-msxml-dom-in-nav.aspx
Bob0
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