Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rpc.call(url, method, ...)
- local JSONRequestArray = {
- id=tostring(math.random()),
- ["method"]=method,
- params = ...
- }
- local jsonRequest = minetest.write_json(JSONRequestArray)
- local httpResponse = http.fetch_async_get(
- http.fetch_async(
- { ['url'] = url,
- method = 'POST',
- extra_headers = { ['content-type']='text/plain', ['content-length']=string.len(jsonRequest) },
- post_data = jsonRequest
- }
- )
- )
- -- Check the http response code
- if (httpResponse.code~=200) then
- return nil, "HTTP ERROR: " .. httpResponse.code
- end
- return minetest.parse_json(httpResponse.data).result, nil
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement