Page 1 of 1

posting data to website

Posted: Tue Jul 16, 2013 9:15 pm
by marcelbohmer
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

Re: posting data to website

Posted: Wed Jul 17, 2013 12:47 am
by SurferTim
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

Re: posting data to website

Posted: Wed Jul 17, 2013 10:20 am
by marcelbohmer
Thanks it worked :)

Re: posting data to website

Posted: Wed Jul 17, 2013 2:12 pm
by SurferTim
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.

Re: posting data to website

Posted: Fri Jul 19, 2013 9:57 pm
by marcelbohmer
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

Re: posting data to website

Posted: Fri Jul 19, 2013 10:41 pm
by SurferTim
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

Re: posting data to website

Posted: Sat Jul 20, 2013 10:05 am
by marcelbohmer
I still gives me the same error

Re: posting data to website

Posted: Sat Jul 20, 2013 12:42 pm
by SurferTim
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.

Re: posting data to website

Posted: Mon Jul 22, 2013 9:49 am
by marcelbohmer
I see it works on v5, they must of change something on v6

Re: posting data to website

Posted: Mon Jul 22, 2013 12:38 pm
by SurferTim
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". ??

Re: posting data to website

Posted: Fri Aug 02, 2013 4:59 pm
by marcelbohmer
I see they have fixed it on V6.2 :D :D :D

Re: posting data to website

Posted: Sat Jun 17, 2017 10:07 pm
by videoicu
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?