mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2014
Posts: 215
J
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
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Mar 2014
Posts: 215
J
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
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
I edited the code right after posting, you must have been lurking the thread..


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Mar 2014
Posts: 215
J
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
Joined: Mar 2014
Posts: 215
J
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
Joined: Mar 2014
Posts: 215
J
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
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Mar 2014
Posts: 215
J
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
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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
}


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Mar 2014
Posts: 215
J
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
Joined: Mar 2014
Posts: 215
J
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

Link Copied to Clipboard