I have been writing a client for Odin's Master.
Im having trouble with the HTTP Post request. It appears that the coljure is executed asynchronously that would at least explain the kind of issues Im having.
- Can I make it synchronous instead?
- Is this even the cause of my problem?
This is the exact code in question:
Code:
def jsonRPC2Request = { url, requestId, method, params ->
def baseUrl = new URL(url)
def p = groovy.json.JsonOutput.toJson(params)
def queryString = '{"json-rcp": "2.0", "id": "'+requestId+'", "method": "'+method+'", "params": '+p+'}'
def connection = baseUrl.openConnection()
connection.with {
doOutput = true
requestMethod = 'POST'
outputStream.withWriter { writer ->
writer << queryString
}
def jsonSlurper = new groovy.json.JsonSlurper()
def object = jsonSlurper.parseText(content.text)
return object
}
}
It is called in various places all over the script however if I put a wait of 2 seconds after the call to the function it works more way more often (not all the time).
The full source code is at GitHub under github.com/OneAndOnlyOdin/VMasterSexScriptsClient/blob/master/main.groovy
Any help would be greatly appreciated.