ya…
I followed this example as much as possible (https://github.com/coronalabs/plugins-sample-openssl/blob/master/luasec/main.lua)
I had to use the openssl plugin (https://docs.coronalabs.com/plugin/openssl/index.html)
so I could use luasec’s https method which has documentation here: (https://github.com/brunoos/luasec/wiki/LuaSec-0.7),
which only explains what’s different from this documentation (which is what I mostly used): (http://w3.impa.br/~diego/software/luasocket/reference.html).
Here’s what I came out with. (I only need patch with certain parameters so I hard coded a lot of it and just overrode the network api in main)
mynetwork.lua
local MyNetwork = {} -- local json = require('json') local openssl = require('plugin.openssl') -- local socket = require('socket') -- local http = require('socket.http') local ltn12 = require('ltn12') -- local plugin\_luasec\_ssl = require('plugin\_luasec\_ssl') local plugin\_luasec\_https = require('plugin\_luasec\_https') -- local lfs = require('lfs') MyNetwork.patchRequest = function( params, callback ) local body = params.body or {}--String local headers = params.headers or {} --table local url = params.url --String local output = {} --[[In case of failure, the function returns nil followed by an error message. If successful, the simple form returns the response body as a string, followed by the response status code, the response headers and the response status line. The generic function returns the same information, except the first return value is just the number 1 (the body goes to the sink). if error one: nil two: error Message else one:(String) response body two: response status code responseHeaders: response headers responseStatusLine: response status line]] local one, two, responseHeaders, responseStatusLine = plugin\_luasec\_https.request({ url = url, sink = ltn12.sink.table(output), protocol = "any", method = "PATCH", headers= { ['Cache-Control']='no-cache', -- headerparam= 'headerValue', ['Content-Type']= 'application/json', ['proxy-connection']= 'keep-alive', ['accept-language']= 'en-US,en;q=0.9', -- ['accept-encoding']= 'gzip',--'gzip, deflate',--HAD TO REMOVE FOR FIREBASE!!! ['Content-Length']=string.len(body), accept= 'text/plain', unpack(headers) }, source= ltn12.source.string(body), }) print("responseHeaders") pprint(responseHeaders) print("responseStatusLine") print(responseStatusLine) if one == nil then -- ERROR callback({isError = true, message=two}) else callback({isError = false, response=output}) end end return MyNetwork
main.lua
local advancedNetwork = require("res.advancednetwork") local baseNetworkRequest = network.request network.request = function( url, method, listener, params ) if method == "PATCH" then advancedNetwork.patchRequest(url, listener, params) else baseNetworkRequest( url, method, listener, params ) end end
build.settings
["plugin.openssl"] = { publisherId = "com.coronalabs", },