Understanding network.request parameters

Good day, I would like to understand the Corona’s way to send a GET and POST Method to my PHP.

On my POST Method everything is fine with this kind of code:

local function saveListener( event ) if ( event.isError ) then print( "Network error: ", event.response ) else print ( "RESPONSE: " .. event.response ) end end local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "filename=".. file .."&something=".. some) local params = {} params.headers = headers params.body = body network.request( "urltoPHPfile.php", "POST", saveListener, params )

There is no error here everything is okay but when I use the GET Method, I can’t find my “filename” and “somnething” on the body parameters to my PHP, when I do it with HTML, it’s okay.

Thanks in advance

HTTP GET expects key-value pairs to be part of the URL. It does not use a “body” concept. URL’s have a length limit, so it only works for URL’s in the 256 max character limit. HTTP POST exists to allow you to send bigger blocks of data to your server script.

To use HTTP GET you would do:

local params = {} params.headers = headers network.request( "urltoPHPfile.php?filename=".. file .. "&something="..some, "GET", saveListener, params)

Rob

Oh, so I did that, I thought there is another way other than the code you just showed. Thanks :slight_smile:

HTTP GET expects key-value pairs to be part of the URL. It does not use a “body” concept. URL’s have a length limit, so it only works for URL’s in the 256 max character limit. HTTP POST exists to allow you to send bigger blocks of data to your server script.

To use HTTP GET you would do:

local params = {} params.headers = headers network.request( "urltoPHPfile.php?filename=".. file .. "&something="..some, "GET", saveListener, params)

Rob

Oh, so I did that, I thought there is another way other than the code you just showed. Thanks :slight_smile: