String over HTTP to PHP

Hi Group,

I want to send a simple string over HTTP to a server using

network.request( url, method, listener [, params] )

I have tried every possible way I can google, but the only string I receive at the PHP side is

0—0-2015-12-16 21:16:25

Which actually is only “0—0” and the timestamp. Whatever I try to put in the params filed, the only output is “0—0”.

Can anybody help me out here?

To be a little more specific, my code looks like this

local params = {}

params.body = “Hello kitty”

network.request(“http://xxxxxxxx/stat/test/save_incoming_test.php”, “POST”, networkListener, params)

Now I would expect the PHP to show

Hello Kitty-2015-12-16 21:16:25

But it doesn’t.

I think you also need to add headers to your params table:

local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local params = {} params.headers = headers params.body = "Hello Kitty"

Thanks for your advice, happymongoose! I will test this tonight (European time) and post the result here.

Edit: Sorry, this didn’t help. Any other suggestion is highly apreciated :slight_smile:

Is your PHP code accessing the data through a $_POST variable?

No, we use $_GET -method, not $_POST.
It’s just a *.php -file for receiving data from a “push” -device.

In that case you don’t need to send any headers or params.  Just open the page with the parameters passed in the URL.

Something like:

network.request("http://xxxxxxxx/stat/test/save\_incoming\_test.php?data=Hello%20Kitty", "GET", networkListener)

Your PHP code to grab the data then looks like this:

$param = $\_GET['data'];

Remember to sanitise any data that gets passed to your webpage otherwise you’ll leave yourself open to injection attacks. 

Thanx, happymongoose, that did the trick!  :slight_smile:

To be a little more specific, my code looks like this

local params = {}

params.body = “Hello kitty”

network.request(“http://xxxxxxxx/stat/test/save_incoming_test.php”, “POST”, networkListener, params)

Now I would expect the PHP to show

Hello Kitty-2015-12-16 21:16:25

But it doesn’t.

I think you also need to add headers to your params table:

local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local params = {} params.headers = headers params.body = "Hello Kitty"

Thanks for your advice, happymongoose! I will test this tonight (European time) and post the result here.

Edit: Sorry, this didn’t help. Any other suggestion is highly apreciated :slight_smile:

Is your PHP code accessing the data through a $_POST variable?

No, we use $_GET -method, not $_POST.
It’s just a *.php -file for receiving data from a “push” -device.

In that case you don’t need to send any headers or params.  Just open the page with the parameters passed in the URL.

Something like:

network.request("http://xxxxxxxx/stat/test/save\_incoming\_test.php?data=Hello%20Kitty", "GET", networkListener)

Your PHP code to grab the data then looks like this:

$param = $\_GET['data'];

Remember to sanitise any data that gets passed to your webpage otherwise you’ll leave yourself open to injection attacks. 

Thanx, happymongoose, that did the trick!  :slight_smile: