mIRC Home    About    Download    Register    News    Help

Topic Options
#247735 - 24/08/14 09:19 PM making a post request to a server
judge2020 Offline
Fjord artisan

Registered: 21/03/14
Posts: 215
Loc: USA
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

Top
#247736 - 24/08/14 09:49 PM Re: making a post request to a server [Re: judge2020]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3465
Loc: France
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)
  }
}


Edited by Wims (24/08/14 09:58 PM)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#247737 - 24/08/14 10:05 PM Re: making a post request to a server [Re: Wims]
judge2020 Offline
Fjord artisan

Registered: 21/03/14
Posts: 215
Loc: USA
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

Top
#247738 - 24/08/14 10:08 PM Re: making a post request to a server [Re: judge2020]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3465
Loc: France
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

Top
#247739 - 24/08/14 10:10 PM Re: making a post request to a server [Re: Wims]
judge2020 Offline
Fjord artisan

Registered: 21/03/14
Posts: 215
Loc: USA
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

Top
#247742 - 24/08/14 11:02 PM Re: making a post request to a server [Re: judge2020]
judge2020 Offline
Fjord artisan

Registered: 21/03/14
Posts: 215
Loc: USA
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

Top
#247745 - 24/08/14 11:19 PM Re: making a post request to a server [Re: judge2020]
judge2020 Offline
Fjord artisan

Registered: 21/03/14
Posts: 215
Loc: USA
could it be easier if you did hadd %sw?
_________________________
#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball

Top
#247746 - 24/08/14 11:46 PM Re: making a post request to a server [Re: judge2020]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3465
Loc: France
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


Edited by Wims (25/08/14 12:00 AM)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#247749 - 25/08/14 01:23 AM Re: making a post request to a server [Re: Wims]
judge2020 Offline
Fjord artisan

Registered: 21/03/14
Posts: 215
Loc: USA
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

Top
#247750 - 25/08/14 02:05 AM Re: making a post request to a server [Re: judge2020]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3465
Loc: France
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

Top
#247838 - 30/08/14 05:30 AM Re: making a post request to a server [Re: Wims]
judge2020 Offline
Fjord artisan

Registered: 21/03/14
Posts: 215
Loc: USA
that worked, thanks :P
_________________________
#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball

Top
#248689 - 18/10/14 02:13 PM Re: making a post request to a server [Re: Wims]
judge2020 Offline
Fjord artisan

Registered: 21/03/14
Posts: 215
Loc: USA
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


Edited by judge2020 (18/10/14 02:30 PM)
_________________________
#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball

Top