tool fetch - 2xx HTTP response codes

Hello!

In process of setup Dude SMS notification using fetch tool we noticed that it fail on 202 HTTP response code from the web server. As a result script fails and stop.

According to the Wikipedia: List of HTTP status codes:

2xx Success

This class of status codes indicates the action requested by the client was received, understood, accepted, and processed successfully.

We have performed simple tests using service http://httpstat.us:

tool fetch url="http://httpstat.us/200"   
      status: finished
  downloaded: 0KiBC-z pause]
       total: 0KiB
    duration: 1s



tool fetch url="http://httpstat.us/202"
  status: failed

failure: closing connection: <202 Accepted> 23.99.0.12:80 (4)

200 OK - status: finished
201 Created - status: failed
202 Accepted - status: failed
203 Non-Authoritative Information - status: failed
204 No Content - status: failed
205 Reset Content - status: failed
206 Partial Content - status: failed

The question is if this behavior is correct?

For example wget:

wget http://httpstat.us/202
echo %errorlevel%
0
#
wget http://httpstat.us/404
echo %errorlevel%
8

From Mikrotik support I get the following workaround:

:do {<SOME COMMAND>} on-error={:put command failed, continue script}

And also found some recent discussion on the forum:

  1. using /tool fetch to create a connection check script
  2. How to verify result of fetch upload to FTP server?

As a result, if we need to run same request 2 time, we can try to use something like this:

:do {
/tool fetch url="http://httpstat.us/202" keep-result=no
} on-error={
/tool fetch url="http://httpstat.us/202" keep-result=no
}

If we need to run it 3 time:

:do {
/tool fetch url="http://httpstat.us/202" keep-result=no
} on-error={
:do {
/tool fetch url="http://httpstat.us/202" keep-result=no
} on-error={
/tool fetch url="http://httpstat.us/202" keep-result=no
}
}

Thank you!

This was solved in the ROS 6.41rc37

What’s new in 6.41rc37 (2017-Oct-02 06:47):

*) fetch - accept all HTTP 2xx status codes;

Now we may run fetch each after another, if web server return 202 and other 2xx status codes:

 
/tool fetch url="http://httpstat.us/202" keep-result=no
/tool fetch url="http://httpstat.us/202" keep-result=no
/tool fetch url="http://httpstat.us/202" keep-result=no

Thank you Mikrotik team!

Hello,

I do have a simular problem:
I want to implement a digest web authentification.
The first step is to do a request to the server. The server will answer with 401 error but addional infos in the response.
How to caputure the responce into a textfile or variable?
Mikrotik scripting is not accepting 4xx errors.

Any suggestions?

regards

I also need to use Digest Authentication.

I have found an MD5 implementation for RouterOS, but did not find any way to get the http response headers on fetch command even on 200 responses.