I’ve been developing an app that communicates with a RESTful web service and I noticed that Corona on Android doesn’t support PUT requests. Is giving me a Null Pointer exception. GET and POST seem to work fine. The problem is when I change the request type to PUT. Do you guys know if this is a known bug? I’m testing it on a Samsung Galaxy S4.
I’m pretty sure PUT works on Android. Can you post your request and maybe a link to the REST service you are using?
Rob
The REST service is custom made for the app but is pretty simple. POST works fine and PUT works on iPhone but not on Android.
Ok, I made a very simple app to test this and, indeed, the PUT request does not work on the Android or at least on the Samsung Galaxy S4. Here’s the code:
local network = require("network") local json = require("json") local url = "http://httpbin.org/put" local listener = function(event) if ( event.isError ) then print("There was an error with the request.") else print (event.response) end end local params = {} params.body = json.encode({msg = "Hello, world"}) network.request(url, "PUT", listener, params)
Here’s what adb gives me:
V/Corona (10057): > Class.forName: network.LuaLoader
V/Corona (10057): < Class.forName: network.LuaLoader
V/Corona (10057): Loading via reflection: network.LuaLoader
V/Corona (10057): > Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona (10057): < Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona (10057): Loading via reflection: CoronaProvider.licensing.google.LuaLoader
I/Corona (10057): Runtime error
I/Corona (10057): java.lang.NullPointerException
I/Corona (10057): Java Stack Trace:
I/Corona (10057): network.NetworkRequest$NetworkRequestParameters.extractRequestParameters(NetworkRequest.java:884)
I/Corona (10057): network.NetworkRequest.invoke(NetworkRequest.java:1883)
I/Corona (10057): com.ansca.corona.JavaToNativeShim.nativeResize(Native Method)
I/Corona (10057): com.ansca.corona.JavaToNativeShim.resize(JavaToNativeShim.java:317)
I/Corona (10057): com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onSurfaceChanged(CoronaGLSurfaceView.java:358)
I/Corona (10057): com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1611)
I/Corona (10057): com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1377)
I/Corona (10057): stack traceback:
I/Corona (10057): [C]: ?
I/Corona (10057): [C]: in function ‘request’
I/Corona (10057): ?: in main chunk
I/Corona (10057): Runtime error
I/Corona (10057):
I/Corona (10057): stack traceback:
I/Corona (10057): [C]: ?
I/Corona (10057): [C]: in function ‘request’
I/Corona (10057): ?: in main chunk
Isn’t the PUT restricted only for binary files?
[quote name=“Renato - RBG” post=“235427” timestamp=“1394318740”]Isn’t the PUT restricted only for binary files?[/quote] What do you mean by that? The PUT request is used when you’re updating a resource. That is the standard for RESTful web services.
Actually here is a good definition of the difference between PUT and POST: http://restcookbook.com/HTTP%20Methods/put-vs-post/
I’m pretty sure PUT works on Android. Can you post your request and maybe a link to the REST service you are using?
Rob
The REST service is custom made for the app but is pretty simple. POST works fine and PUT works on iPhone but not on Android.
Ok, I made a very simple app to test this and, indeed, the PUT request does not work on the Android or at least on the Samsung Galaxy S4. Here’s the code:
local network = require("network") local json = require("json") local url = "http://httpbin.org/put" local listener = function(event) if ( event.isError ) then print("There was an error with the request.") else print (event.response) end end local params = {} params.body = json.encode({msg = "Hello, world"}) network.request(url, "PUT", listener, params)
Here’s what adb gives me:
V/Corona (10057): > Class.forName: network.LuaLoader
V/Corona (10057): < Class.forName: network.LuaLoader
V/Corona (10057): Loading via reflection: network.LuaLoader
V/Corona (10057): > Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona (10057): < Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona (10057): Loading via reflection: CoronaProvider.licensing.google.LuaLoader
I/Corona (10057): Runtime error
I/Corona (10057): java.lang.NullPointerException
I/Corona (10057): Java Stack Trace:
I/Corona (10057): network.NetworkRequest$NetworkRequestParameters.extractRequestParameters(NetworkRequest.java:884)
I/Corona (10057): network.NetworkRequest.invoke(NetworkRequest.java:1883)
I/Corona (10057): com.ansca.corona.JavaToNativeShim.nativeResize(Native Method)
I/Corona (10057): com.ansca.corona.JavaToNativeShim.resize(JavaToNativeShim.java:317)
I/Corona (10057): com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onSurfaceChanged(CoronaGLSurfaceView.java:358)
I/Corona (10057): com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1611)
I/Corona (10057): com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1377)
I/Corona (10057): stack traceback:
I/Corona (10057): [C]: ?
I/Corona (10057): [C]: in function ‘request’
I/Corona (10057): ?: in main chunk
I/Corona (10057): Runtime error
I/Corona (10057):
I/Corona (10057): stack traceback:
I/Corona (10057): [C]: ?
I/Corona (10057): [C]: in function ‘request’
I/Corona (10057): ?: in main chunk
Isn’t the PUT restricted only for binary files?
[quote name=“Renato - RBG” post=“235427” timestamp=“1394318740”]Isn’t the PUT restricted only for binary files?[/quote] What do you mean by that? The PUT request is used when you’re updating a resource. That is the standard for RESTful web services.
Actually here is a good definition of the difference between PUT and POST: http://restcookbook.com/HTTP%20Methods/put-vs-post/
Was this ever resolved? I’m bumping into the same bug. Emulator and iOS work fine, but Android gives theNullPointerException.
I don’t see a bug report referencing Android and PUT. Our engineers cannot look into this with out a bug report. Bug reports must contain a main.lua, config.lua and a build.settings along with any assets needed to reproduce the problem. Put all of that in a .zip file and use the Report a Bug link at the top. When you get the confirmation email, please post the Case ID # back here.
Thanks
Rob
Submitted as case 42281
Was this ever resolved? I’m bumping into the same bug. Emulator and iOS work fine, but Android gives theNullPointerException.
I don’t see a bug report referencing Android and PUT. Our engineers cannot look into this with out a bug report. Bug reports must contain a main.lua, config.lua and a build.settings along with any assets needed to reproduce the problem. Put all of that in a .zip file and use the Report a Bug link at the top. When you get the confirmation email, please post the Case ID # back here.
Thanks
Rob
Submitted as case 42281