Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Network.request() body is empty
Started by ddubya82 Mar 23 2019 10:44 AM

4 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ddubya82

[GLOBAL: userInfoPane.html]
ddubya82
  • Enthusiast

  • 41 posts
  • Corona SDK

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.



[TOPIC: post.html]
#2

ddubya82

[GLOBAL: userInfoPane.html]
ddubya82
  • Enthusiast

  • 41 posts
  • Corona SDK

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?



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,801 posts
  • Enterprise

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

 

Rob



[TOPIC: post.html]
#4

ddubya82

[GLOBAL: userInfoPane.html]
ddubya82
  • Enthusiast

  • 41 posts
  • Corona SDK

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.  :)

 

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



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,801 posts
  • Enterprise

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




[topic_controls]
[/topic_controls]