sending and Getting data from a site

Hey Guys,

I’ve corona sdk since 2017 but, I’ve never done anything with the network request. I’m currently building a HTML 5 game that requires getting and updating information ona server and using it to determine the player’s progression.

For example, I create a variable called “openStages”, an integer which determines the number of stages opened at the level selection page, if the players opens two stages, then this variable is equal to (2), then I send this number to a server and next time the player opens the game, this variable is called from the server and used to determine the number of stages that should be opened.

I’ve gone through the network request API and I can’t seem to get it working. Here’s an example below. Please how do I get this working.

local function networkListener( event )
 
    if ( event.isError ) then
        print( "Network error: ", event.response )
    else
        print ( "RESPONSE: " … event.response )
    end
end
 
local headers = {}
local body = “Hello”
 
local params = {}
params.headers = headers
headers[“Username”] = “soccerrtest”
headers[“Password”] = “htqry”
params.body = body

 
network.request( “http://45.58.119.26/cloudagents/api/gametest”, “POST”, networkListener, params )

Your code seems to be set up in a way that everything should work, so what do you mean when you say that it doesn’t work? Is it that you don’t get any response in your console? Is it only not working on your server? Or is it not returning what you expected it to return?

Also, please use the code formatting tools.

In the code that you posted, there’s no mention of this openStages variable that you are supposed to be sending. We also have no idea what your server is supposed to do, etc. Essentially, the code that you’ve provided should work exactly as it is written, you make a network request and you get something back.

The question is: what are you expecting to happen?

Thanks for replying. That was just an example.

Here’s the real detail.

The endpoint is —       http://45.58.119.26/cloudbetagents/api/gametest

The username is —     soccerravegametest

The password is —      “123@1#-%3*”

The hashkey is —        “Soccerravetest1234#”

The hash formular is sha512(username+password+hashkey)

This was the information I got from the network guys, I’ve never used an Hashkey before, I don’t even know how to arrange this. I’ve been battling it for weeks, I’m almost at the point of giving up.

Given the information above, How do I structure the code to get the payload at that endpoint, what would the code look like ?

Thank you.

I am sorry, but there’s no way to help you with the given information.

You can create a hash based on your information via: 

local crypto = require( "crypto" ) local hash = crypto.digest( crypto.sha512, username .. password .. hashkey ) 

https://docs.coronalabs.com/api/library/crypto/sha512.html

But the real issue is still how the back end works, i.e. what information does it actually expect to be passed, in what manner, and what information will it then return, etc.

You just need to read the documentation for whatever service you are using as your back end.

Thanks, You’ve helped a lot. I’ll write the code and post of copy of it here later, can you help with a comment or review.