mIRC Home    About    Download    Register    News    Help

Print Thread
making a post request to a server #247735 24/08/14 08:19 PM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
very bad (if i'm anything at all) with making http requests, just want to make a post request to a server.
can someone create a quick alias and signal for this?

server to post to:
Code:
https://toontowninfinite.com/api/login/

the post request:
Code:
n=ircCheckr&p=judge2020&dist=test

the request header:
Code:
POST /api/login/ HTTP/1.1
Host: toontowninfinite.com
Accept: */*
Content-Length: 33
Content-Type: application/x-www-form-urlencoded

the response should be something like this:
Code:
{"success":false,blablablabla

and it always sends a 200 OK even if success is false. is there a way i can check for the success being false or true instead of checking for 200 OK?


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Re: making a post request to a server [Re: judge2020] #247736 24/08/14 08:49 PM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
Check http://en.wikichip.org/wiki/mirc/sockets/tcp for more informations
Code:
alias toon {
 if (!$sslready) return $input(SSL is required,o)
 sockclose toon
 sockopen -e toon toontowninfinite.com 443
}
on *:sockopen:toon:{
 if ($sockerr) return $input(Error while trying to connect to the server,o)
 var %sw sockwrite -n toon
 %sw POST /api/login/
 %sw Host: toontowninfinite.com
 %sw Content-Length: 34
 %sw
 sockwrite toon n=ircCheckr&p=judge2020&dist=test
}
on *:sockread:toon:{
  if ($sockerr) return $input(An error occured while reading data,o)
  var %a
  sockread -f %a
  if (*{"success":* iswm %a) {
     echo -a success : $gettok($gettok(%a,2,58),1,44)
  }
}

Last edited by Wims; 24/08/14 08:58 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: making a post request to a server [Re: Wims] #247737 24/08/14 09:05 PM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
Originally Posted By: helpfile
/sockopen [-de] [bindip] <name> <address> <port>

reading help files and that page, it requires a name. change it to
Code:
  sockopen -e toon toontowninfinite.com 443
but now it's giving no input...


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Re: making a post request to a server [Re: judge2020] #247738 24/08/14 09:08 PM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
I edited the code right after posting, you must have been lurking the thread..


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: making a post request to a server [Re: Wims] #247739 24/08/14 09:10 PM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
ya, now it works. thanks for the help, going to hook it up to a 10 second timer to check if the status changes smile


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Re: making a post request to a server [Re: judge2020] #247742 24/08/14 10:02 PM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
i keep getting false and error invalid distribution, on requestmaker.com the same n=ircCheckr&p=judge2020&dist=test works so i know it's not that


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Re: making a post request to a server [Re: judge2020] #247745 24/08/14 10:19 PM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
could it be easier if you did hadd %sw?


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Re: making a post request to a server [Re: judge2020] #247746 24/08/14 10:46 PM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
I also got that error when trying it.
I don't know what to tell you, I just wrote what you asked for, the server is answering (you said it would answer 200 OK, but it does not answer 200 OK at all, it sends some lines full of $chr(32) and then send the JSON data.)

It wouldn't be easier to use an hash table here, unsure what you have in mind, I used a variable to avoid repeating the "sockwrite -n $sockname" stuff, makes the request clearer

Last edited by Wims; 24/08/14 11:00 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: making a post request to a server [Re: Wims] #247749 25/08/14 12:23 AM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
well when i use a request maker i get HTTP/1.1 200 OK so...


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Re: making a post request to a server [Re: judge2020] #247750 25/08/14 01:05 AM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
Eh, seeing "HTTP/1.1" in your post helped, that's actually my bad, I forgot to put the HTTP version to use in the POST line, I also counted 34 bytes for the length, but you were right with 33, that didn't fix the problem though, so I added the header you specified in your first post and it worked wink

Update the on sockopen event:
Code:
on *:sockopen:toon:{
  if ($sockerr) return $input(Error while trying to connect to the server,o)
  var %sw sockwrite -n toon
  %sw POST /api/login/ HTTP/1.1
  %sw Host: toontowninfinite.com
  %sw Accept: */*
  %sw Content-Type: application/x-www-form-urlencoded
  %sw Content-Length: 33
  %sw
  sockwrite toon n=ircCheckr&p=judge2020&dist=test
}


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: making a post request to a server [Re: Wims] #247838 30/08/14 04:30 AM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
that worked, thanks :P


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Re: making a post request to a server [Re: Wims] #248689 18/10/14 01:13 PM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
so coming back to this, i am now using an API to check the status. it was easy altering the toon socket to work with this, but i have a problem.

the $gettok in the sockread event does not work the same as the old one. the old was
Code:
{"success":true/false...
but now it's
Code:
{"public":"1"}
so the current gettok is getting "1"} instead of a just 1 or just 0

thanks for any help
EDIT: nevermind, found $gettok(%a,4,34) to work

Last edited by judge2020; 18/10/14 01:30 PM.

#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball