I’m beginner in Lua. I would like to use this code to send high scores to server.
local function networkListener( event ) if ( event.isError ) then print( "Network error!") else print ( "RESPONSE: " .. event.response ) end end network.request( "http://samplesite.com/addscore.php?name="Joe"&score=100", "POST", networkListener, params)
I don’t know, How can I use variable name and score in http parameters. Please, help me.
Though, if you do it that way (putting everything into the URL), I think it should be a “GET”, not a “POST” … not entirely sure. A more traditional “POST” would look like:
@jbl1 When posting you can also put parameters in url (as in GET), but as you mentioned POST have body and all data should be there (it can take a lot more data then you would be able to put in url, eg. files).
@gryzio55 method is just fine for hardcoded test - just one problem: you try to put quotation marks inside quotation marks - it’s no-no in any string handling language!
You have single (’) and double (") ones for commbination, so if you want to put string in string then: “He said ‘hello’ to me” or ‘He said “hello” to me’.
Also, in your example you do not need to put marks around Joe - url will be decoded on server just fine.
Though, if you do it that way (putting everything into the URL), I think it should be a “GET”, not a “POST” … not entirely sure. A more traditional “POST” would look like:
@jbl1 When posting you can also put parameters in url (as in GET), but as you mentioned POST have body and all data should be there (it can take a lot more data then you would be able to put in url, eg. files).
@gryzio55 method is just fine for hardcoded test - just one problem: you try to put quotation marks inside quotation marks - it’s no-no in any string handling language!
You have single (’) and double (") ones for commbination, so if you want to put string in string then: “He said ‘hello’ to me” or ‘He said “hello” to me’.
Also, in your example you do not need to put marks around Joe - url will be decoded on server just fine.