Congratulation With New Funny :( Bug With Network 2.0 "post" Request On Android!

Hi Corona team,

bug is very simple:

 

Code:

 

function listener( event )

    print( "RESPONSE: "…tostring(event.response) )

    print( "EVENT.phase: "…tostring(event.phase) )

    print( "EVENT.status: "…tostring(event.status) )

    print( "EVENT.responseType: "…tostring(event.responseType) )

    if ( event.isError ) then

    else return event.response end

    return nil

end

 

network.request( SERVER_URL…"/token", “POST”, listener, { body = “access_token=”…at } )

 

Result on iOS and Simulator:

RESPONSE: OK

EVENT.phase: ended

EVENT.status: 200

EVENT.responseType: text

 

Result on Android:

RESPONSE: nil

EVENT.phase: ended

EVENT.status: 200

EVENT.responseType: nil

 

I know very well corona team,**  So I answer future questions:**

 

1.  usesPermissions =

            {

                “android.vending.BILLING”,

                “android.permission.INTERNET”,

                “android.permission.READ_PHONE_STATE”,

                “android.permission.ACCESS_NETWORK_STATE”,

            },

2. Build  1056

3. All ok with server (all requests tested manually)

4. Public release work without problems.

5. Bug issued with “POST” requests only. “GET” work w/o bugs.

 

Thanks.

 

 

 

 

Confirmed same error on POST requests. Working on simulator, but not Android device nor Android Emulator. Build 1056, 1057.

 

This is the networkRequest event returned to the listener:

 

 

------------ Table: Network error! -------------

I/Corona  ( 3244): [responseHeaders] => Table

I/Corona  ( 3244):                {

I/Corona  ( 3244):                  [Connection] => keep-alive

I/Corona  ( 3244):                  [Content-Length] => 420

I/Corona  ( 3244):                  [X-Android-Received-Millis] => 1363761000765

I/Corona  ( 3244):                  [Date] => Wed, 20 Mar 2013 06:29:58 GMT

I/Corona  ( 3244):                  [X-Android-Sent-Millis] => 1363760998458

I/Corona  ( 3244):                  [HTTP-STATUS-LINE] => HTTP/1.1 200 OK

I/Corona  ( 3244):                }

I/Corona  ( 3244): [phase] => ended

I/Corona  ( 3244): [bytesEstimated] => 420

I/Corona  ( 3244): [name] => networkRequest

I/Corona  ( 3244): [bytesTransferred] => 0

I/Corona  ( 3244): [status] => 200

I/Corona  ( 3244): [url] => http://192.168.1.71:8081/refresh

I/Corona  ( 3244): [isError] => true

I/Corona  ( 3244): [requestId] => false

I/Corona  ( 3244): --------------------------------------------------------------

 

Nathan.

SOLVED: 

 

I figured out that POST breaks because I set the response content-type to ‘application/json’ on the server.

NOT SOLVED!!!

 

response content-type is ‘text’ on the server!!!

 

Corona team - fix this bug!!!

Confirmed same error on POST requests. Working on simulator, but not Android device nor Android Emulator. Build 1056, 1057.

 

This is the networkRequest event returned to the listener:

 

 

------------ Table: Network error! -------------

I/Corona  ( 3244): [responseHeaders] => Table

I/Corona  ( 3244):                {

I/Corona  ( 3244):                  [Connection] => keep-alive

I/Corona  ( 3244):                  [Content-Length] => 420

I/Corona  ( 3244):                  [X-Android-Received-Millis] => 1363761000765

I/Corona  ( 3244):                  [Date] => Wed, 20 Mar 2013 06:29:58 GMT

I/Corona  ( 3244):                  [X-Android-Sent-Millis] => 1363760998458

I/Corona  ( 3244):                  [HTTP-STATUS-LINE] => HTTP/1.1 200 OK

I/Corona  ( 3244):                }

I/Corona  ( 3244): [phase] => ended

I/Corona  ( 3244): [bytesEstimated] => 420

I/Corona  ( 3244): [name] => networkRequest

I/Corona  ( 3244): [bytesTransferred] => 0

I/Corona  ( 3244): [status] => 200

I/Corona  ( 3244): [url] => http://192.168.1.71:8081/refresh

I/Corona  ( 3244): [isError] => true

I/Corona  ( 3244): [requestId] => false

I/Corona  ( 3244): --------------------------------------------------------------

 

Nathan.

SOLVED: 

 

I figured out that POST breaks because I set the response content-type to ‘application/json’ on the server.

NOT SOLVED!!!

 

response content-type is ‘text’ on the server!!!

 

Corona team - fix this bug!!!

Any news on a fix for this?

Hello,

I just tried this on build 1076 and its working.

That’s strange because it is still broken for me in 1076 and the latest 1086. The iOS version of my game never had an issue, but the Android version of my game stopped working after 1041. Any attempt to POST crashes the app, so my ptoject is stuck using 1041.

Hmm, do you have some sample code?  

Maybe I’ll have more time later to write a sample, but basicaly if I use network.request call to POST some data and if the “Content-Type” is set to “application/json”, it will crash on my Android tablet. If I chnage it to something like “text” it doesn’t crash, but then my POST call is incorrect.

    local headers = {}     headers["Content-Type"]           = "application/json"     headers["X-Parse-Application-Id"] = G.parseAppId     headers["X-Parse-REST-API-Key"]   = G.parseRestAPIKey     headers["X-Parse-Session-Token"]  = G.parseSessionToken     local params = {}     params.headers = headers     local message =     {         game\_id = G.currentGameId,         user\_id = G.userObjectId,         data = json.encode( moveData ),         move\_number = G.currentGameNumMoves + 1     }     params.body = json.encode( message )     native.setActivityIndicator( true )     network.request( G.parseBaseUrl .. "classes/Move", "POST", createMoveListener,  params )  

The crash looks like this when runing logcat:

E/SurfaceFlinger(  104): SurfaceFlinger translucent=0 isOpaque=1 isExternalDisplayLayer=0 isExternalBlockLayer0
W/System.err( 3645): com.naef.jnlua.LuaRuntimeException: ?:0: attempt to index a nil value
W/System.err( 3645):     at com.naef.jnlua.LuaState.lua_pcall(Native Method)
W/System.err( 3645):     at com.naef.jnlua.LuaState.call(Unknown Source)
W/System.err( 3645):     at com.ansca.corona.CoronaLua.dispatchEvent(CoronaLua.java:74)
W/System.err( 3645):     at network.NetworkRequest$LuaCallback$1.executeUsing(NetworkRequest.java:598)
W/System.err( 3645):     at com.ansca.corona.CoronaRuntimeTaskDispatcher$TaskEvent.Send(CoronaRuntimeTaskDispatcher.java:153)
W/System.err( 3645):     at com.ansca.corona.events.EventManager.sendEvents(EventManager.java:274)
W/System.err( 3645):     at com.ansca.corona.Controller.onDrawFrame(Controller.java:233)
W/System.err( 3645):     at com.ansca.corona.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:379)
W/System.err( 3645):     at com.ansca.corona.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1622)
W/System.err( 3645):     at com.ansca.corona.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1377)

I have further narrowed it down to missing data in the event passed into my listener.

For example, when I POST something succesfully from the simulator or from an iOS device, I get back this as the event table:

{     responseHeaders =     {         Access-Control-Allow-Origin = "\*",         Content-Type = "application/json; charset=utf-8",         Date = "Tue, 23 Apr 2013 02:48:52 GMT",         Set-Cookie = "\_parse\_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlNWQ4ZjMyZTlmNWRiMDQxYTAyM2ViMjZiMDIyMmYyYTQ%3D--39d76bd6cbdf29c9f6ea923befeaffa47411b0bd; domain=.parse.com; path=/; expires=Sun, 23-Apr-2023 02:48:52 GMT; secure; HttpOnly",         Access-Control-Request-Method = "\*",         Status = "201 Created",         Location = "https://api.parse.com/1/classes/Game/VfsDRgyzkN",         Cache-Control = "no-cache",         Connection = "keep-alive",         X-Runtime = "0.058573",         Content-Length = "64",         X-UA-Compatible = "IE=Edge,chrome=1",         Server = "nginx/1.2.2",     },     responseType = "text",     phase = "ended",     bytesEstimated = 64,     response = "{"createdAt":"2013-04-23T02:48:52.895Z","objectId":"VfsDRgyzkN"}",     name = "networkRequest",     bytesTransferred = 64,     status = 201,     url = "https://api.parse.com/1/classes/Game",     isError = false,     requestId = userdata: 0x109315fb8, }  

Note how the response var has something in it:

response = “{“createdAt”:“2013-04-23T02:48:52.895Z”,“objectId”:“VfsDRgyzkN”}”

Now, on Android I get nothing back in the response var even though the POST suceeded:

{     responseHeaders =     {         Access-Control-Allow-Origin = "\*",         Content-Length = "64",         X-UA-Compatible = "IE=Edge,chrome=1",         X-Runtime = "0.220905",         Date = "Tue, 23 Apr 2013 02:43:42 GMT",         Set-Cookie = "\_parse\_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlYmVmZWUzNzUzODhiMDkwY2IxNWY1NjRlZmE3NTdiYzc%3D--37c47909943ae8189d856595df066364392aca85; domain=.parse.com; path=/; expires=Sun, 23-Apr-2023 02:43:42 GMT; secure; HttpOnly",         Access-Control-Request-Method = "\*",         X-Android-Sent-Millis = "1366771317313",         Connection = "keep-alive",         Status = "201 Created",         Cache-Control = "no-cache",         X-Android-Received-Millis = "1366771318017",         Location = "https://api.parse.com/1/classes/Game/TVPJIwJGno",         Content-Type = "application/json; charset=utf-8",         HTTP-STATUS-LINE = "HTTP/1.1 201 Created",         Server = "nginx/1.2.2",     },     responseType = "text",     phase = "ended",     bytesEstimated = 0,     response = "",     name = "networkRequest",     bytesTransferred = 0,     status = 201,     url = "https://api.parse.com/1/classes/Game",     isError = false,     requestId = false, }  

Does anyoine have a clue why this would be? This code has been working perfectly for over 6 months, but now I get no data back an Android.

Any news on a fix for this?

The next Daily Build (2013.2094 or later) should fix the problem with 201 responses which were being treated slightly differently to those with 200 codes.

This was the only problem I was able to find POSTing data on Android after a bunch of testing.  If still have problems using the fixed build, please send us a reproducible case and note the device and Android version you are seeing the error on.

Hello,

I just tried this on build 1076 and its working.

That’s strange because it is still broken for me in 1076 and the latest 1086. The iOS version of my game never had an issue, but the Android version of my game stopped working after 1041. Any attempt to POST crashes the app, so my ptoject is stuck using 1041.

Hmm, do you have some sample code?  

Thanks. My Android builds are back to working as of build 2013.1094.

Maybe I’ll have more time later to write a sample, but basicaly if I use network.request call to POST some data and if the “Content-Type” is set to “application/json”, it will crash on my Android tablet. If I chnage it to something like “text” it doesn’t crash, but then my POST call is incorrect.

    local headers = {}     headers["Content-Type"]           = "application/json"     headers["X-Parse-Application-Id"] = G.parseAppId     headers["X-Parse-REST-API-Key"]   = G.parseRestAPIKey     headers["X-Parse-Session-Token"]  = G.parseSessionToken     local params = {}     params.headers = headers     local message =     {         game\_id = G.currentGameId,         user\_id = G.userObjectId,         data = json.encode( moveData ),         move\_number = G.currentGameNumMoves + 1     }     params.body = json.encode( message )     native.setActivityIndicator( true )     network.request( G.parseBaseUrl .. "classes/Move", "POST", createMoveListener,  params )  

The crash looks like this when runing logcat:

E/SurfaceFlinger(  104): SurfaceFlinger translucent=0 isOpaque=1 isExternalDisplayLayer=0 isExternalBlockLayer0
W/System.err( 3645): com.naef.jnlua.LuaRuntimeException: ?:0: attempt to index a nil value
W/System.err( 3645):     at com.naef.jnlua.LuaState.lua_pcall(Native Method)
W/System.err( 3645):     at com.naef.jnlua.LuaState.call(Unknown Source)
W/System.err( 3645):     at com.ansca.corona.CoronaLua.dispatchEvent(CoronaLua.java:74)
W/System.err( 3645):     at network.NetworkRequest$LuaCallback$1.executeUsing(NetworkRequest.java:598)
W/System.err( 3645):     at com.ansca.corona.CoronaRuntimeTaskDispatcher$TaskEvent.Send(CoronaRuntimeTaskDispatcher.java:153)
W/System.err( 3645):     at com.ansca.corona.events.EventManager.sendEvents(EventManager.java:274)
W/System.err( 3645):     at com.ansca.corona.Controller.onDrawFrame(Controller.java:233)
W/System.err( 3645):     at com.ansca.corona.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:379)
W/System.err( 3645):     at com.ansca.corona.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1622)
W/System.err( 3645):     at com.ansca.corona.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1377)