Community discussions

MikroTik App
 
marcelbohmer
just joined
Topic Author
Posts: 12
Joined: Wed Mar 10, 2010 8:14 am

posting data to website

Tue Jul 16, 2013 9:15 pm

Hi

Im trying to post data to a url (http://ipaddress/phpscript.php?number=*********&msg=********)

If I use /tool fetch url="http://ipaddress/phpscript.php?number=*********&msg=********" mode=http
I get action invalid(6)

Is there any other way to do this?

Thanks
 
SurferTim
Forum Guru
Forum Guru
Posts: 4637
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: posting data to website

Wed Jul 17, 2013 12:47 am

This worked for me. The question mark must be escaped with the backslash and the path enclosed in double quotes. All one line.
/tool fetch mode=http address=1.2.3.4 src-path="/phpscript.php\?number=2" dst-path=phpscript.php
You can use script variables in that also. If you have a environment variable called "$number", then you can use this to send it in the url. All one line.
/tool fetch mode=http address=1.2.3.4 src-path="/phpscript.php\?number=$number" dst-path=phpscript.php
 
marcelbohmer
just joined
Topic Author
Posts: 12
Joined: Wed Mar 10, 2010 8:14 am

Re: posting data to website

Wed Jul 17, 2013 10:20 am

Thanks it worked :)
 
SurferTim
Forum Guru
Forum Guru
Posts: 4637
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: posting data to website

Wed Jul 17, 2013 2:12 pm

Good deal. If you did not figure out the rest, the result of the request (webpage minus the header) is in /file in the phpscript.php file.
/file
print detail where name=phpscript.php
If you keep the response page short, you can use the contents to determine the result of the request if it is important.
 
marcelbohmer
just joined
Topic Author
Posts: 12
Joined: Wed Mar 10, 2010 8:14 am

Re: posting data to website

Fri Jul 19, 2013 9:57 pm

If I add $number to the src-path I get an error - end of line expected- on the "u" after the "\?" as marked in red

/tool fetch mode=http address=1.2.3.4 src-path="/phpscript.php\?number=$number" dst-path=phpscript.php
 
SurferTim
Forum Guru
Forum Guru
Posts: 4637
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: posting data to website

Fri Jul 19, 2013 10:41 pm

The variable $number must exist, or it will error like that.
:global number 2;
/tool fetch mode=http address=1.2.3.4 src-path="/phpscript.php\?number=$number" dst-path=phpscript.php
 
marcelbohmer
just joined
Topic Author
Posts: 12
Joined: Wed Mar 10, 2010 8:14 am

Re: posting data to website

Sat Jul 20, 2013 10:05 am

I still gives me the same error
 
SurferTim
Forum Guru
Forum Guru
Posts: 4637
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: posting data to website

Sat Jul 20, 2013 12:42 pm

Check "/system script environment" and insure that variable name is there. If it is not there, I get the same error. If it is there, it works.

I'm using v5.25 for this test.
 
marcelbohmer
just joined
Topic Author
Posts: 12
Joined: Wed Mar 10, 2010 8:14 am

Re: posting data to website

Mon Jul 22, 2013 9:49 am

I see it works on v5, they must of change something on v6
 
SurferTim
Forum Guru
Forum Guru
Posts: 4637
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: posting data to website

Mon Jul 22, 2013 12:38 pm

I see it works on v5, they must of change something on v6
That makes a person wonder if the script is supposed to work and doesn't with the new version, or wasn't supposed to work before and has been "fixed". ??
 
marcelbohmer
just joined
Topic Author
Posts: 12
Joined: Wed Mar 10, 2010 8:14 am

Re: posting data to website

Fri Aug 02, 2013 4:59 pm

I see they have fixed it on V6.2 :D :D :D
 
videoicu
just joined
Posts: 15
Joined: Sat Aug 07, 2010 4:11 pm

Re: posting data to website

Sat Jun 17, 2017 10:07 pm

I have a similar problem with the question mark ? in a script.

ROS v6.39.2

I have this code in a script and it returns an error (status: failed, failure: closing connection: <unknown protocol:) when I execute the script via terminal CLI /system/script run x or simply fails if I run it in winbox in the script.
/tool fetch mode=http keep-result=no url="http://192.168.0.137/gpsgateserver/
gpsgate.aspx/\?longitude=$newlong&latitude=$newlat&speed=0.0&date=$vdate&time=$nctime&username=mtg
ps&IMEI=admin";
The issue appears to be with the .......aspx/?......which is the format needed to send to the server.
From the prior posts I added the backslash \ before the ? to escape but the script still fails......aspx/\?

NOW if I run the same code directly from the terminal CLI, it runs and is accepted by website for input. Terminal CLI returns: status: finished
/tool fetch mode=http keep-result=no url="http://192.168.0.137/gpsgate
server/gpsgate.aspx/\?longitude=$newlong&latitude=$newlat&speed=0.0&date=$vdate&time=$nctime&username=mt
gps";

I have tried it with and without the backlash \ escape character before the ? but I get the same failed result
I have also downgraded to 5.26 with no luck either.

Can someone that has experienced this please help solve this problem?

Who is online

Users browsing this forum: No registered users and 13 guests