I need to create a script that will download a file from source that presented as 301 redirect in DNS
Data.mydomain.com —A ->301->
https://mysite/file.rsc
Fetch data.mydomain.com gives an error to download file.rsc due to 301 redirect usage
Any ideas what to do?
The
HTTP specs suggests a client (e.g. /tool/fetch) MAY,
e.g. not MUST, follow a HTTP 301 redirect,
6.4.2. 301 Moved Permanently
The server SHOULD generate a Location header field in the response containing a preferred URI reference for the new permanent URI. The user agent MAY use the Location field value for automatic redirection. The server's response payload usually contains a short hypertext note with a hyperlink to the new URI(s). The user agent MAY use the Location field value for automatic redirection. The server's response payload usually contains a short hypertext note with a hyperlink to the new URI(s).
While /tool/fetch doesn't return the actual 301 error code, or any HTTP error codes, which makes /tool/fetch even more limited. It does return the body of the requests, which should have the "Location:" in the data returned even after a 301 "error". So theoretically, you can parse the data returned from first call to /tool/fetch, e.g. using :find / :pick to find the text "Location:" and then the URL. Again here RouterOS script doesn't have built-in string parsing either, so you need write that (or search the forum for examples / "library"). e.g. like @rextended's example linked above:
viewtopic.php?p=878643#p878643
SO while I think its possible to do with a script, but you may be
better offer working to get someone to fix the webserver/URL paths to avoid needing what would be a rather complex RouterOS script.