fetch capable of following redirects

search tag # rextended manage fetch errors

I write one post a time, leave me the time!!! :laughing: :laughing: :laughing:

Is not for suspance, I need some time to write and test…

This is the code:

/file remove [find where name="testfetch.txt"]
{
    :local jobid [:execute file=testfetch.txt script="/tool fetch url=http://mikrotik.com"]
    :put "Waiting the end of process for file testfetch.txt to be ready, max 20 seconds..."
    :global Gltesec 0
    :while (([:len [/sys script job find where .id=$jobid]] = 1) && ($Gltesec < 20)) do={
        :set Gltesec ($Gltesec + 1)
        :delay 1s
        :put "waiting... $Gltesec"
    }
    :put "Done. Elapsed Seconds: $Gltesec\r\n"
    :if ([:len [/file find where name="testfetch.txt"]] = 1) do={
        :local filecontent [/file get [/file find where name="testfetch.txt"] contents]
        :put "Result of Fetch:\r\n****************************\r\n$filecontent\r\n****************************"
    } else={
        :put "File not created."
    }
}

This is the result:
Waiting the end of process for file testfetch.txt to be ready, max 20 seconds…
waiting… 1
waiting… 2
Done. Elapsed Seconds: 2

Result of Fetch:


status: connecting

status: failed

failure: closing connection: <302 Found “https://mikrotik.com/”> 159.148.147.196:80 (4)


the result is a multiline file between the ****************************

with :find and :pick inside the string “closing connection: <302 Found “https://mikrotik.com/”> 159.148.147.196:80 (4)” can be isolated

the part containing the redirect “https://mikrotik.com/

you can recall again the test code and you discover another redirect to “https://www.mikrotik.com/:laughing: :laughing: :laughing:

End.