tool fetch xml

Hello,

I am trying to control a device that the API outputs XML as a result of a GET. I don’t care about the output, I just want to send a command with the API, but a required part of the API string tells it to output XML, so it always sends back a response. Easily ignored in curl.

So:

/tool fetch mode=http  url=http://192.168.1.134/state.xml?<some command string> 
status: failed
failure: ERROR parsing http: error in line

I’ve tried various permutations including by address and src-path, with output=user, as-value to no avail.

Am I doing it wrong or missing arguments or does fetch just not like getting back XML?

For reference, this is what it sends back with curl:

curl "http://192.168.1.134/state.xml?<some command string>"
<?xml version="1.0" encoding="utf-8" ?>
<datavalues>
...

In case it matters, I’ve tried it on ROS 7.15.1 and 7.15.3.

I think you need to read little more about the api and the fetch command.
https://help.mikrotik.com/docs/display/ROS/Fetch
https://help.mikrotik.com/docs/display/ROS/REST+API
You need some more settings like http-method http-header-field http-data.

@sbotnick This is not related to fetch command arguments, even mode is not necessary for http(s) and http-method argument is GET by default if not specified.
Try to fetch for eg. https://mocktarget.apigee.net/xml which also responds with XML and it will work -

/tool/fetch url=http://mocktarget.apigee.net/xml

Mentioned error is related to parsing HTTP protocol data from response, can be corrupted response when fetching from ROS (partial or no HTTP protocol data) or complete response data for some reason breaks fetch (unlikely).
You can use Packet Sniffer tool, while sniffer is running perform fetch from ROS and examine if HTTP response is valid.

Since curl defaults to GET, and that works… my guess is some escaping issue in the URL - as OP show just “” …while the URL itself shouldn’t require any escaping as shown… depending what in the ?query params part, that may need escaping.

So I’d try putting quotes around the url=“http://…” and see what that gets you. If you have a $ or “, those need $ or " escapes (inside the url=”…" outer quotes, to be clear).

Also, you may want to add an “output=user” to your /tool/fetch, to view the results at the CLI.

If query arguments are not encoded correctly, HTTP server should respond with some HTTP error code if there is some wrong value and fetch failure message will be formatted depending on HTTP response code, eg. Fetch failed with status 400, but if HTTP service is not responding by standard and wrong values in url results respond without data or not HTTP protocol data then error mentioned in OP could happen.
Still I will suggest to examine HTTP request and response from sniffer (by examining packets it is visible how characters are encoded in request), also examining logs on HTTP service side if exists won’t hurt…

Thanks all for the input!

You gave me the idea to fetch the root and I got a 401 error! Somebody password protected it on me, that was not expected. The server put out the correct response on the root request but not on the state.xml request when authentication was not included. I added authentication to fetch command and it does the job. I should have checked to see that things were working as expected in other ways.

Beverages on me.

FWIW, this fetch is going into a watchdog script to make a PDU power cycle the upstream DSL modem when the router loses Internet connection.

Addendum: My older devices only speak HTTP/0.9 and newer versions of curl don’t work at all and wget requires -O- to force it, I assume m’tik uses one of those and it won’t work with them, unfortunately. Works fine with the newer series of device that speak 1.x.

Hi, I’m very glad you solved the problem, but I and the forum would be so much happier
if you also mark your case in this forum as solved.

See the pictures below.
Where you click on the following places on the thread that solved your problem.

So the AI can take over and know what the problems are with the respective solution.

At board style: Canvas

At board style: prosilver