Community discussions

MikroTik App
 
danmiles86
just joined
Topic Author
Posts: 13
Joined: Thu Mar 24, 2016 10:54 pm

Simple HTTP GET?

Wed May 11, 2016 1:11 am

I'm having some trouble with what I thought would be simple! I just need a script for my router to connect to my home automation to power cycle some devices as required. It just needs to open a link in the form off the following;

http://192.168.20.11:3480/data_request? ... getValue=0

I've tried a few things like;

/tool fetch url="http://192.168.20.11:3480/data_request? ... ormat=json"

/tool fetch address=192.168.20.11 src-path=data_request?id=action&DeviceNum=113&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0 port=3480 mode=http

But keep getting various errors, mainly failed (6).

I don't need to keep the returned XML file, just as long as the GET request has gone through. I'm hoping to use the script in Netwatch Down.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Simple HTTP GET?

Wed May 11, 2016 3:10 am

You need to escape the "?", as it triggers the help, and in turn doesn't get added to the URL, causing a wrong URL to be called, in turn causing a 404, in turn causing the error message.

i.e. use
/tool fetch url="http://192.168.20.11:3480/data_request\?id=action&DeviceNum=113&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&output_format=json"
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
danmiles86
just joined
Topic Author
Posts: 13
Joined: Thu Mar 24, 2016 10:54 pm

Re: Simple HTTP GET?

Wed May 11, 2016 12:48 pm

Thank you, thank you, thank you! I wansn't even thinking of this as a possibility and I would have been hours stressing over this. Worked first time. :D

I don't suppose you also know how I can modify this so it doesn't save the file or automatically deletes it?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Simple HTTP GET?

Wed May 11, 2016 8:48 pm

/tool fetch url="http://192.168.20.11:3480/data_request\?id=action&DeviceNum=113&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&output_format=json" keep-result=no
(notice that last part)
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
jeroenp
Member Candidate
Member Candidate
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam
Contact:

Re: Simple HTTP GET?

Thu May 12, 2016 12:58 am

Just in case you ever need it, a list of escapes is in the scripting language manual.
 
danmiles86
just joined
Topic Author
Posts: 13
Joined: Thu Mar 24, 2016 10:54 pm

Re: Simple HTTP GET?

Thu May 12, 2016 2:09 am

Thank you. Sorry the second part was simple and should have got that myself. Very much appreciate the help.

Who is online

Users browsing this forum: No registered users and 16 guests