Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
UrlLoader.POST of JSON document works in player, Windows, not Android — Gideros Forum

UrlLoader.POST of JSON document works in player, Windows, not Android

PaulHPaulH Member
edited November 2016 in General questions
Hey, folks. I'm stumped with a networking issue. I have code that builds a JSON document and uses a UrlLoader to post it to a PHP script on the web. In the player on Windows it works fine, but on Android the UrlLoader just triggers an Event.ERROR. Other UrlLoaders in the same app work fine, but they use GET rather than POST.

The code is pretty simple:

local json = (a simple json document in a string)
local path = "http://(my domain)/(a php script).php"

local headers =
{
["Content-Type"] = "application/json",
["Content-Length"] = string.len(json)
}
local loader = UrlLoader.new(path, UrlLoader.POST, headers, json)

Any ideas? Any different headers that might need to be set?

The reason for this, if anyone is curious: The app I'm preparing to release will get content on a subscription basis. The JSON post tells the server the user's subscription status (a set of receipts from IAB) and the server responds with a set of links to content packages the user is entitled to download.

Paul

Comments

  • EricCarrEricCarr Member
    edited December 2016 Accepted Answer
    I think it sets the content length for you.

    I use this in Android, and it works just fine:
    payload = data
     
    local loader = UrlLoader.new(
     serverUrl, 
     UrlLoader.POST, 
     {["Content-Type"]="application/json"}, 
     json.encode(payload)
    )
  • Bingo! I just removed the length from the header and it works. I never would have thought to try removing that. Thank you!
Sign In or Register to comment.