Community discussions

MikroTik App
 
jeanribeiro87
just joined
Topic Author
Posts: 5
Joined: Thu May 20, 2021 6:00 pm

tool fetch http post txt

Tue Nov 09, 2021 7:10 am

Good evening everyone.
Please help me to upload the content of a text file via the fetch tool. I have been trying and failing constantly.
The code I'm using is as follows:
:local s "{:put [/ip arp print]}"
/tool fetch mode=http url=https://webhook.site/efc9b9df-e142-48a2-8ae9-9f70750787ca http-data=[:execute script=$s ]
I've tried to save to file but was unsuccessful, I read on the forum that this is because the ROS only reads files up to 4096B, so I used this variable "s". Needless to say, I was not successful. Any help is welcome.
/ip arp print file=test
/tool fetch mode=http url=https://webhook.site/efc9b9df-e142-48a2-8ae9-9f70750787ca http-data=[/file get test.txt contents]
 
User avatar
antonsb
MikroTik Support
MikroTik Support
Posts: 388
Joined: Sun Jul 24, 2016 3:12 pm
Location: Riga, Latvia

Re: tool fetch http post txt

Wed Nov 10, 2021 12:12 pm

you are missing http-method
 
jeanribeiro87
just joined
Topic Author
Posts: 5
Joined: Thu May 20, 2021 6:00 pm

Re: tool fetch http post txt

Wed Nov 10, 2021 1:20 pm

you are missing http-method
First thanks for the reply.
Even using http-method it doesn't send, I tried using all (post, get and put).
 
sin3vil
newbie
Posts: 34
Joined: Sat May 26, 2018 10:05 pm

Re: tool fetch http post txt  [SOLVED]

Wed Nov 10, 2021 9:41 pm

I think the main issue in your method is not the post itself, rather, the collection of data.
:execute runs something in the background with no interaction with the current terminal session.
print only echos to the terminal. You cannot save the print output or pass it elsewhere without using as-value, which returns an array of dictionary items.
The print to file would work but is limited to RouterOSs stupid 4096 byte limitation when working with files. If your arp table's output is larget than 4096 characters it won't load it back.

You can use something like this.
{ 
local data [/ip arp print as-value]
/tool fetch url="https://ptsv2.com/t/fwdrm-1636572193/post" http-method=post http-data=$data http-header-field="Content-Type: text/text"
}
 
jeanribeiro87
just joined
Topic Author
Posts: 5
Joined: Thu May 20, 2021 6:00 pm

Re: tool fetch http post txt

Fri Nov 12, 2021 4:39 am

I think the main issue in your method is not the post itself, rather, the collection of data.
:execute runs something in the background with no interaction with the current terminal session.
print only echos to the terminal. You cannot save the print output or pass it elsewhere without using as-value, which returns an array of dictionary items.
The print to file would work but is limited to RouterOSs stupid 4096 byte limitation when working with files. If your arp table's output is larget than 4096 characters it won't load it back.

You can use something like this.
{ 
local data [/ip arp print as-value]
/tool fetch url="https://ptsv2.com/t/fwdrm-1636572193/post" http-method=post http-data=$data http-header-field="Content-Type: text/text"
}

Exactly what I needed. It worked perfectly and for that I am very grateful.

Thanks a lot for the help.

Who is online

Users browsing this forum: No registered users and 34 guests