To my surprise, the standard fetch tool in routerOS has no option to deal with following redirect.
So I decided to enhance it by scripting a function that would loop x times the fetch, each loop with the url pointing towards the redirect provided by the previous iteration.
My issue is that I don't think the scripting language enables me to do such basic task: it seems that the fetch command throws an error when facing a 301 (or 302).
So I can't consume what if the 302 pointing towards in order to loop again towards that new target.
- if I run fetch without error handling, the script stops at the fetch command
- if I run fetch with error handing, then the script resumes, but I get no output from the fetch action, and consequently can't assess where to redirect to
Would you have any advise how to overcome this?
Sample script below that shows a redirect on mikrotik.com website.
I would be keen to get a script POC that manages to extract where the redirect points towards
Code: Select all
:do {:local output [/tool fetch url="http://mikrotik.com/" as-value output="user" mode="http"];} on-error={
:put "error handling";
:put $output; # shows nothing when error is triggered
}