Empty Internet cache/temp from NAV after connect. url?

BlackMagicBlackMagic Member Posts: 38
Hi people.

Im working on a project where I need to periodically connecting an URL to get a XML file for updating the Item Card in NAV. The URL connecting code is look like this:

Variables:
XMLhttp: 'Microsoft XML, v3.0'.XMLHTTP
connStr: Text
XMLDOMDoc: 'Microsoft XML, v3.0'.DOMDocument

Code
CREATE(XMLhttp);
XMLhttp.open('get',connStr,FALSE); //Connecting url (= connStr)
XMLhttp.send;

IF ISCLEAR(XMLDOMDoc) THEN
CREATE(XMLDOMDoc);

XMLDOMDoc := XMLhttp.responseXML;
XMLDOMDoc.save(_savePath); //Saving the XML file locally


There is no problem with connecting the URL and saving the XML file. But my problem is that if I dont restart Navision after each connecting time, then it just download the cached/temporary XML file from last time, so that I will not get the new updated data.

My question is therefore, how can I clear this cache from NAV so that it will download the new XML file each time when I run the code?

Is there an automation for this, or can you recommend another method for getting the new XML file.

Thank for advance.

Comments

  • kinekine Member Posts: 12,562
    May be you can add some HTTP header to include no-cache setting.

    Adding something like thisinto HTTP request header:
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">

    when getting the document...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • BlackMagicBlackMagic Member Posts: 38
    Hi Kine good idea. But i cannot make use of this solution, because i request the XML file just by connecting af internet url that look like: http://...filename.xml and not via XML request.
  • kinekine Member Posts: 12,562
    You are using XMLHTTP class - it is sending HTTP request, answer is the XML file. Do not mix XML and HTTP. The automation have function "setRequestHeader", where you can set the parameters of the HTTP header which will be send to the server.

    it means add something like this:
    XMLhttp.setRequestHeader('Pragma','no-cache');
    XMLhttp.setRequestHeader('Cache-Control','no-cache');
    XMLhttp.setRequestHeader('Expires','Sat, 01 Dec 2001 00:00:00 GMT');
    XMLhttp.Send;
    

    This will add HTTP header parameters. For more info search something more about HTTP headers like there: http://www.cs.tut.fi/~jkorpela/http.html
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ayhan06ayhan06 Member Posts: 210
    BlackMagic wrote:
    Hi people.

    Im working on a project where I need to periodically connecting an URL to get a XML file for updating the Item Card in NAV. The URL connecting code is look like this:

    Variables:
    XMLhttp: 'Microsoft XML, v3.0'.XMLHTTP
    connStr: Text
    XMLDOMDoc: 'Microsoft XML, v3.0'.DOMDocument

    Code
    CREATE(XMLhttp);
    XMLhttp.open('get',connStr,FALSE); //Connecting url (= connStr)
    XMLhttp.send;

    IF ISCLEAR(XMLDOMDoc) THEN
    CREATE(XMLDOMDoc);

    XMLDOMDoc := XMLhttp.responseXML;
    XMLDOMDoc.save(_savePath); //Saving the XML file locally


    There is no problem with connecting the URL and saving the XML file. But my problem is that if I dont restart Navision after each connecting time, then it just download the cached/temporary XML file from last time, so that I will not get the new updated data.

    My question is therefore, how can I clear this cache from NAV so that it will download the new XML file each time when I run the code?

    Is there an automation for this, or can you recommend another method for getting the new XML file.

    Thank for advance.
    // XmlDocIn = 'Microsoft XML, v3.0'.DOMDocument
    CREATE(XmlDocIn);
    XmlDocIn.async := FALSE;
    IF NOT  XmlDocIn.load('http://www.xyxyxy.com.tr') THEN
      ERROR('error text');
    

    I am using this method without problem.. i am sure that evenif http response is not signed as "no-cache" or expiration date, this works..

    also you can try POST method instead of GET. as far as i remember, web server and browser do not process cached documets when POST method is used.
  • ferrysbferrysb Member Posts: 14
    Hi All,

    I also have same problem like BlackMagic.
    I already tried
    XmlDomDoc.async = FALSE

    and


    XMLHttp.setRequestHeader('Pragma','no-cache');
    XMLHttp.setRequestHeader('Cache-Control','no-cache');
    XMLHttp.setRequestHeader('Expires','Sat, 01 Dec 2001 00:00:00 GMT');


    but still can't worked. The XML seems to be saved somehow on the cache, because it will return same xml everytime.

    Please advise
    many thanks for your help
Sign In or Register to comment.