How to prevent XMLHTTP to get client-side cached result?

pdj
Member Posts: 643
NAV2009 R2 Classic - I am downloading an XML file using this code:
The first time it works fine. The second time I get the exact same cached XML file, and I keep getting the same cached XML until I restart NAV. Then I get a new version of the XML file. I can also open the URL in Internet Explorer, and each time I open the URL in IE it also updates the client-side cache and I get the new version in NAV.
(I can also open the URL in Edge, but this doesn't update the client-side cache used by IE and "NAV")
How can I prevent my code to get a cached version of the XML file?
l_XMLHTTP: Automation 'Microsoft XML, v6.0'.XMLHTTP60 l_XMLDomDoc: Automation 'Microsoft XML, v6.0'.DOMDocument60 l_InStream: InStream CREATE(l_XMLHTTP); l_XMLHTTP.open('GET','HTTP://SomeDomain/SimpleRESTService',FALSE,'SomeUser','SomePwd'); l_XMLHTTP.setRequestHeader('Cache-Control','max-age=0'); l_XMLHTTP.send(); l_InStream := l_XMLHTTP.responseStream; CLEAR(l_XMLHTTP); CREATE(l_XMLDomDoc); l_XMLDomDoc.async := FALSE; IF NOT l_XMLDomDoc.load(l_InStream) THEN ERROR('Unable to load XML');
The first time it works fine. The second time I get the exact same cached XML file, and I keep getting the same cached XML until I restart NAV. Then I get a new version of the XML file. I can also open the URL in Internet Explorer, and each time I open the URL in IE it also updates the client-side cache and I get the new version in NAV.
(I can also open the URL in Edge, but this doesn't update the client-side cache used by IE and "NAV")
How can I prevent my code to get a cached version of the XML file?
Regards
Peter
Peter
0
Best Answer
-
Thank you for your reply.
I have not been able to get a result with POST - it kept giving me an error.
However; I managed to solve the issue by adding a dummy parameter with a random value:l_XMLHTTP.open('GET','HTTP://SomeDomain/SimpleRESTService'+STRSUBSTNO('?x=%1',CREATEGUID),FALSE,'SomeUser','SomePwd');
Not pretty, but it seems to be a common solution to prevent cachingRegards
Peter0
Answers
-
Hi,
I´ve made webservice calls using automations in the past and I never had that issue.
Can I suggest try with POST?
Also, try it in postman tool, see how it behaves.
Also try to clear l_InStream variable.
1 -
Thank you for your reply.
I have not been able to get a result with POST - it kept giving me an error.
However; I managed to solve the issue by adding a dummy parameter with a random value:l_XMLHTTP.open('GET','HTTP://SomeDomain/SimpleRESTService'+STRSUBSTNO('?x=%1',CREATEGUID),FALSE,'SomeUser','SomePwd');
Not pretty, but it seems to be a common solution to prevent cachingRegards
Peter0 -
I'm sorry I had to reject your answer and that it now is "red", like it is a "bad" answer, which is isn't !Regards
Peter0
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