Here's a rather crude example here to get you rolling with $urlget()
alias NJSUser {
var %URI = http://localhost , %JSON = $+({"username":,",$1,"})
bset -t &headers 1 Content-Type: application/json
bset -t &body 1 %JSON
noop $urlget(%URI,pbi,&NJSUser,processNJS,&headers,&body)
}
alias processNJS {
var %id = $1 , %BV = $urlget(%id).target
echo -ai2 * ID: %id , Bvar: %BV , Size: $bvar(%BV,0)
if ($bvar(%BV,0)) { echo -ai2 * Data: $bvar(%BV,1-).text }
}
Example: /njsuser foo
mIRC's $URLGet() output to connection (socket spied upon to clarify what mIRC already adds to the "headers"):
POST / HTTP/1.1
Accept: */*
Content-Type: application/json
Accept-Encoding: gzip, deflate
User-Agent: mIRC
Host: localhost
Content-Length: 18
Connection: Keep-Alive
Cache-Control: no-cache
{"username":"foo"}
Using urlget, you will notice things like Host, Content-Length, User-Agent, etc.. are already done for you, so we only need to add the content-type which is nice.
The breakdown: $urlget(%URI,pbi,&NJSUser,processNJS,&headers,&body)
uri = target...
p = post method, b = binary mode, i = ignore ssl errors (just in case it may be https:// and a self-signed cert or whatever error)
The first binvar is what we wish the results of request to be filled into (&NJSUser)
processNJS = the alias to call when the request finishes.
&headers = the additional headers we wish to pass
&body = the body of the request (our JSON)
Breakdown part 2:
when urlget is assigned a request, it assigns a unique ID to that request (if we didn't use noop here, the return from using $urlget() would be that ID number just for clarity). If using a callback alias, $1 is the ID of this particular request.
You can pull various information given this ID number via $urlget(id).[property]
Properties are as follows: url, redirect, method, type, target, alias, id, state, size, resume, rcvd, time, reply
In this "crude" example, it will upon completion echo out the ID, binvar used, and the size of the binvar which shows if any data at all was collected, and a very poorly broken (potential line too long error) echo of the return body if the binvar length isn't 0.
Hope this helps you in using $urlget() instead of the raw socket approach, kept it short and simple to not be too conviluted with info. This should get you into the ballpark of valid returns you can then decide what to do with that data.