Network.request() body is empty

Hi all,

I’m trying to hit a custom built service using network.request().  The request is sent to the server, however the body is blank by the time it gets there.  Other than the empty body, the request is successful.

I can hit the service just fine via Postman using the same criteria below.

local headers = {} headers["Content-Type"] = "application/json" headers["Authorization"] = "abc123" headers["langCode"] = "en" local params = { headers = headers, timeout = 30, body = json.encode({ action = "checkForUpdates", dynamicBundleLastUpdatedTimestamp = 0, gameShortCode = "re.taketwo" }) } network.request("http://localhost/webhook", "POST", listener, params)

Any help would be appreciated.

Cheers.

I move the code off of my localhost to see if my WAMP config had anything to do with it.  Now the Simulator works perfect, but building to device still shows an empty body.

The dump of the params table looks good and is identical on both device and Simulator:

{ ["body"] = {"dynamicBundleLastUpdatedTimestamp":0,"action":"checkForUpdates","gameShortCode":"re.taketwo"},["timeout"] = 30,["headers"] = { ["Content-Type"] = application/json,["langCode"] = en,["Authorization"] = abc123,} ,} 

What gives?

Can you be more specific? Are you using PHP? Node.js? Is the server getting an empty body?

Rob

Thanks for getting back, Rob.  Issue is fixed now after I found an old forum post from 2012 that pointed me in the right direction.  I’m using PHP and the server was continuously receiving an empty body.  

I ended up changing everything over from JSON to key/value pairs, Base64 encoded, following the thread below and it’s all working now.  Not sure what the issue was, and now I can’t get the damn thing to fail.  :slight_smile:

Post that helped me:

https://forums.coronalabs.com/topic/24571-resolved-yay-i-cant-get-a-super-basic-http-post-network-request-to-work/page-2

There is some oddities with some hosted versions of PHP that doesn’t properly fill out $_POST[] even though your sending it correctly. That post you referred to fixes the issue.

Rob

I move the code off of my localhost to see if my WAMP config had anything to do with it.  Now the Simulator works perfect, but building to device still shows an empty body.

The dump of the params table looks good and is identical on both device and Simulator:

{ ["body"] = {"dynamicBundleLastUpdatedTimestamp":0,"action":"checkForUpdates","gameShortCode":"re.taketwo"},["timeout"] = 30,["headers"] = { ["Content-Type"] = application/json,["langCode"] = en,["Authorization"] = abc123,} ,} 

What gives?

Can you be more specific? Are you using PHP? Node.js? Is the server getting an empty body?

Rob

Thanks for getting back, Rob.  Issue is fixed now after I found an old forum post from 2012 that pointed me in the right direction.  I’m using PHP and the server was continuously receiving an empty body.  

I ended up changing everything over from JSON to key/value pairs, Base64 encoded, following the thread below and it’s all working now.  Not sure what the issue was, and now I can’t get the damn thing to fail.  :slight_smile:

Post that helped me:

https://forums.coronalabs.com/topic/24571-resolved-yay-i-cant-get-a-super-basic-http-post-network-request-to-work/page-2

There is some oddities with some hosted versions of PHP that doesn’t properly fill out $_POST[] even though your sending it correctly. That post you referred to fixes the issue.

Rob