network.request not getting a response from Android

I’m implementing the ability to upload and download files to Dropbox. I have it working in the emulator and on iOS. On android, I can download files but not upload. I am testing on a Galaxy 3.

I’ve seen a previous thread on this topic and in that thread Joshua Quick said this is often caused by a header problem in the put request. Based on that advice my url looks like this:

[lua]local url = “https://api-content.dropbox.com/1/files_put/auto/” … path … “?” … authString … “&progress=upload&overwrite=false&accept=*/*&accept-charset=*&accept-language=en-us&accept-encoding=”[/lua]

I realize I can put the headers in a table, but like I said, this construction works just fine on iOS, I’m just trying to make Android happy.

I also have these permissions in the build file:

“android.permission.INTERNET”,

 “android.permission.WRITE_EXTERNAL_STORAGE”,

 “android.permission.ACCESS_NETWORK_STATE”,

The terminal on this G3 is super spammy but I’m pretty sure this is the right error:

Permission Denial: opening provider com.google.android.gsf.gservices.GservicesProvider from ProcessRecord{4471b0e8 25480:com.mycomp.myapp/000000} (pid=00000, uid=00000) requires com.google.android.providers.gsf.permission.READ_GSERVICES or com.google.android.providers.gsf.permission.WRITE_GSERVICES

Any idea what might be causing that error?

[edit] I should note that this app is live and that I’m side loading the test app. Since I added the additional permissions (already had internet) I did not see a prompt to allow the app to have the permissions. Maybe this is normal but I’m not sure. The previous article I referenced above is here: http://forums.coronalabs.com/topic/32967-networkrequest-failing-on-android-over-ssl/

I’m still working on this problem.

I discovered that the header “Content-Length” is needed by Dropbox so I added it. The message is still not being sent.

I’m confident that the request is being composed correctly because as I said before it works in both the emulator and on iOS.

I added an intent filter for “android.intent.action.SEND” but that didn’t seem to do anything. I don’t fully understand intent filters, I think they are kind of like assigning a variable to an operating system controlled function. This would suggest that I would need to call the name of the intent filter in my code like “intent.myaction”. If anyone can confirm or deny that, I am interested.

Does Corona have that intent filter built in for the use of network.request?

Because there are a bunch of things going on on this phone all the time, it’s hard to know which error codes are relevant. However, I’m starting to think that these network errors are from my network.request call:

D/StatusChecker(23381): onReceive : android.intent.action.SERVICE\_STATE D/StatusChecker(23381): Service state changed : 0 E/MP-Decision( 2335): num online cores: 2 reqd : 4 available : 4 rq\_depth:4.000000 hotplug\_avg\_load\_dw: 60 E/MP-Decision( 2335): UP cpu:1 core\_idx:1 Nw:1.900000 Tw:140 rq:4.000000 seq:0.000000 E/MP-Decision( 2335): UP cpu:2 core\_idx:2 Nw:2.700000 Tw:90 rq:4.000000 seq:146.000000 E/MP-Decision( 2335): UP cpu:3 core\_idx:3 Nw:3.500000 Tw:90 rq:4.000000 seq:146.000000 E/MP-Decision( 2335): num online cores: 4 reqd : 2 available : 4 rq\_depth:0.300000 hotplug\_avg\_load\_dw: 45 E/MP-Decision( 2335): DOWN cpu:3 core\_idx:3 Ns:3.100000 Ts:240 rq:0.300000 seq:245.000000 E/MP-Decision( 2335): DOWN cpu:2 core\_idx:2 Ns:2.100000 Ts:240 rq:0.300000 seq:245.000000 D/STATUSBAR-NetworkController( 1221): onSignalStrengthsChanged signalStrength=SignalStrength: 99 99 -90 -30 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 cdma 0x30 level=3 D/STATUSBAR-NetworkController( 1221): refreshSignalCluster: data=-1 bt=false D/STATUSBAR-IconMerger( 1221): checkOverflow(504), More:true, Req:true Child:9 I/ActivityManager(  815): Waited long enough for: ServiceRecord{44e41ad8 u0 com.amazon.venezia/com.amazon.mas.client.locker.service.appmgr.AppManagerService} W/EDMNativeHelper(  270): EDMNativeHelperService is published D/STATUSBAR-NetworkController( 1221): onReceive() - RSSI\_CHANGED\_ACTION, WIFI\_STATE, NETWORK\_STATE D/STATUSBAR-NetworkController( 1221): refreshSignalCluster: data=-1 bt=false D/STATUSBAR-IconMerger( 1221): checkOverflow(504), More:true, Req:true Child:9 E/MP-Decision( 2335): num online cores: 2 reqd : 1 available : 4 rq\_depth:1.100000 hotplug\_avg\_load\_dw: 24 E/MP-Decision( 2335): DOWN cpu:1 core\_idx:1 Ns:1.100000 Ts:190 rq:1.100000 seq:196.000000 D/STATUSBAR-NetworkController( 1221): onSignalStrengthsChanged signalStrength=SignalStrength: 99 99 -91 -35 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 cdma 0x30 level=3 D/STATUSBAR-NetworkController( 1221): onSignalStrengthsChanged signalStrength=SignalStrength: 99 99 -91 -35 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 cdma 0x30 level=3 E/MP-Decision( 2335): num online cores: 1 reqd : 4 available : 4 rq\_depth:3.500000 hotplug\_avg\_load\_dw: 42 E/MP-Decision( 2335): UP cpu:1 core\_idx:1 Nw:1.900000 Tw:140 rq:3.500000 seq:98.000000 E/MP-Decision( 2335): UP cpu:2 core\_idx:2 Nw:2.700000 Tw:90 rq:3.500000 seq:98.000000 E/MP-Decision( 2335): UP cpu:3 core\_idx:3 Nw:3.500000 Tw:90 rq:3.500000 seq:98.000000 E/MP-Decision( 2335): num online cores: 4 reqd : 3 available : 4 rq\_depth:0.000000 hotplug\_avg\_load\_dw: 48 E/MP-Decision( 2335): DOWN cpu:3 core\_idx:3 Ns:3.100000 Ts:240 rq:0.000000 seq:241.000000 W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:424) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.NetAPI.execute(ProGuard:212) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.HTTPPostClient.execute(ProGuard:96) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.concrete\_sendpacket(ProGuard:385) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.sendPostPacket(ProGuard:354) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.send(ProGuard:282) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.threads.RequestQueueConsumer.run(ProGuard:30) W/System.err( 5551): at java.lang.Thread.run(Thread.java:841) W/System.err( 5551): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI\_NODATA (No address associated with hostname) W/System.err( 5551): at libcore.io.Posix.getaddrinfo(Native Method) W/System.err( 5551): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61) W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:405) W/System.err( 5551): ... 16 more W/System.err( 5551): Caused by: libcore.io.ErrnoException: getaddrinfo failed: EINVAL (Invalid argument) W/System.err( 5551): ... 19 more W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:424) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.NetAPI.execute(ProGuard:212) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.HTTPPostClient.execute(ProGuard:96) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.concrete\_sendpacket(ProGuard:385) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.sendPostPacket(ProGuard:354) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.send(ProGuard:282) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.threads.RequestQueueConsumer.run(ProGuard:30) W/System.err( 5551): at java.lang.Thread.run(Thread.java:841) W/System.err( 5551): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI\_NODATA (No address associated with hostname) W/System.err( 5551): at libcore.io.Posix.getaddrinfo(Native Method) W/System.err( 5551): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61) W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:405) W/System.err( 5551): ... 16 more W/System.err( 5551): Caused by: libcore.io.ErrnoException: getaddrinfo failed: EINVAL (Invalid argument) W/System.err( 5551): ... 19 more E/[SAEngine]( 5551): retry W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:394) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.NetAPI.execute(ProGuard:212) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.HTTPPostClient.execute(ProGuard:96) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.concrete\_sendpacket(ProGuard:385) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.sendPostPacket(ProGuard:354) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.send(ProGuard:282) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.threads.RequestQueueConsumer.run(ProGuard:39) W/System.err( 5551): at java.lang.Thread.run(Thread.java:841) W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:394) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.NetAPI.execute(ProGuard:212) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.HTTPPostClient.execute(ProGuard:96) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.concrete\_sendpacket(ProGuard:385) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.sendPostPacket(ProGuard:354) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.send(ProGuard:282) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.threads.RequestQueueConsumer.run(ProGuard:39) W/System.err( 5551): at java.lang.Thread.run(Thread.java:841) E/[SAEngine]( 5551): retry W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:394) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)

Ok, I made that error go away by adding back:

“android.permission.ACCESS_NETWORK_STATE”,

I had taken it out because I felt like I was just piling on permissions that didn’t have anything to do with what I was trying to do… this one, in fact was needed.

I hope this helps someone some day, that is why I’m logging my progress. I would love to have someone go, “Oh, I know what he’s doing wrong!” and then post it here but I realize that may not happen.

Are any headers added to the request by network.request()? It seems like you would just automatically add some of them like “Content-Length” being added to a PUT request.

Ok, I fixed this issue. The bottom line is that Android doesn’t like PUT requests. I don’t know why. If you are trying to send a file on an Android device use POST. iOS doesn’t seem to care either way so the platform neutral thing to do is POST.

It was really tough to figure out because nowhere in the error log did it say, “I don’t know what PUT means” or anything like that. I’m just posting this resolution because the solution isn’t really anywhere I could find, I just had to brute force a solution. Hope this helps someone.

Hi, Mark. Couldn’t you share here your code for upload and downloading?

I’m getting some trouble using Michael’s https://code.coronalabs.com/code/dropbox-rest-api-module-corona-sdk. I’m getting some error, and I don’t know where…

Hi Wiler, The only thing I really did different was use a post command instead of a put command:

[lua]

D.putFile = function(path, listener, data, params)

 local url = “https://api-content.dropbox.com/1/files_put/auto/” … path

 params = params or {}

 if not params.headers then

  params.headers = {}

 end

 local headers = params.headers

 headers.Authorization = "OAuth " … string.gsub(authString, “&”, “,”)

 if not headers[“Content-Length”] then

  local fileSize = string.len(data)

  headers[“Content-Length”] = fileSize

 end

 if not params.body then

  params.body = data

 end

 network.request(url, “POST”, getFileListener(listener), params)

end

[/lua]

This is pretty much a cut and paste from my code. I’m using it in several places so I gave myself the option of having a custom body and custom header but the basics default into the POST. How you need to customize it will depend on your app. There are a all kinds of things that might be causing your problem, and they may or may not have anything to do with a POST command. Best thing I can recommend is try to make a separate test app that just uploads a string to DB, get that working and then add the code into your application.

If you want to see the code at work, I have a version of it in this app which was made using Corona SDK: http://www.legendofus.net/wheres-my-sidekick/ I use it both to enable the user to back up files and to enable them to share files. I could never get an email to attach a file on Android so I just upload it to DB and then share a link to the file by email.

One more note, you can still use ‘&’ for options in the POST command… so like after ‘path’ above you could have:

[lua]

… “?option=mychoice&otheroption=mychoice”

[/lua]

I’m still working on this problem.

I discovered that the header “Content-Length” is needed by Dropbox so I added it. The message is still not being sent.

I’m confident that the request is being composed correctly because as I said before it works in both the emulator and on iOS.

I added an intent filter for “android.intent.action.SEND” but that didn’t seem to do anything. I don’t fully understand intent filters, I think they are kind of like assigning a variable to an operating system controlled function. This would suggest that I would need to call the name of the intent filter in my code like “intent.myaction”. If anyone can confirm or deny that, I am interested.

Does Corona have that intent filter built in for the use of network.request?

Because there are a bunch of things going on on this phone all the time, it’s hard to know which error codes are relevant. However, I’m starting to think that these network errors are from my network.request call:

D/StatusChecker(23381): onReceive : android.intent.action.SERVICE\_STATE D/StatusChecker(23381): Service state changed : 0 E/MP-Decision( 2335): num online cores: 2 reqd : 4 available : 4 rq\_depth:4.000000 hotplug\_avg\_load\_dw: 60 E/MP-Decision( 2335): UP cpu:1 core\_idx:1 Nw:1.900000 Tw:140 rq:4.000000 seq:0.000000 E/MP-Decision( 2335): UP cpu:2 core\_idx:2 Nw:2.700000 Tw:90 rq:4.000000 seq:146.000000 E/MP-Decision( 2335): UP cpu:3 core\_idx:3 Nw:3.500000 Tw:90 rq:4.000000 seq:146.000000 E/MP-Decision( 2335): num online cores: 4 reqd : 2 available : 4 rq\_depth:0.300000 hotplug\_avg\_load\_dw: 45 E/MP-Decision( 2335): DOWN cpu:3 core\_idx:3 Ns:3.100000 Ts:240 rq:0.300000 seq:245.000000 E/MP-Decision( 2335): DOWN cpu:2 core\_idx:2 Ns:2.100000 Ts:240 rq:0.300000 seq:245.000000 D/STATUSBAR-NetworkController( 1221): onSignalStrengthsChanged signalStrength=SignalStrength: 99 99 -90 -30 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 cdma 0x30 level=3 D/STATUSBAR-NetworkController( 1221): refreshSignalCluster: data=-1 bt=false D/STATUSBAR-IconMerger( 1221): checkOverflow(504), More:true, Req:true Child:9 I/ActivityManager(  815): Waited long enough for: ServiceRecord{44e41ad8 u0 com.amazon.venezia/com.amazon.mas.client.locker.service.appmgr.AppManagerService} W/EDMNativeHelper(  270): EDMNativeHelperService is published D/STATUSBAR-NetworkController( 1221): onReceive() - RSSI\_CHANGED\_ACTION, WIFI\_STATE, NETWORK\_STATE D/STATUSBAR-NetworkController( 1221): refreshSignalCluster: data=-1 bt=false D/STATUSBAR-IconMerger( 1221): checkOverflow(504), More:true, Req:true Child:9 E/MP-Decision( 2335): num online cores: 2 reqd : 1 available : 4 rq\_depth:1.100000 hotplug\_avg\_load\_dw: 24 E/MP-Decision( 2335): DOWN cpu:1 core\_idx:1 Ns:1.100000 Ts:190 rq:1.100000 seq:196.000000 D/STATUSBAR-NetworkController( 1221): onSignalStrengthsChanged signalStrength=SignalStrength: 99 99 -91 -35 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 cdma 0x30 level=3 D/STATUSBAR-NetworkController( 1221): onSignalStrengthsChanged signalStrength=SignalStrength: 99 99 -91 -35 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 cdma 0x30 level=3 E/MP-Decision( 2335): num online cores: 1 reqd : 4 available : 4 rq\_depth:3.500000 hotplug\_avg\_load\_dw: 42 E/MP-Decision( 2335): UP cpu:1 core\_idx:1 Nw:1.900000 Tw:140 rq:3.500000 seq:98.000000 E/MP-Decision( 2335): UP cpu:2 core\_idx:2 Nw:2.700000 Tw:90 rq:3.500000 seq:98.000000 E/MP-Decision( 2335): UP cpu:3 core\_idx:3 Nw:3.500000 Tw:90 rq:3.500000 seq:98.000000 E/MP-Decision( 2335): num online cores: 4 reqd : 3 available : 4 rq\_depth:0.000000 hotplug\_avg\_load\_dw: 48 E/MP-Decision( 2335): DOWN cpu:3 core\_idx:3 Ns:3.100000 Ts:240 rq:0.000000 seq:241.000000 W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:424) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.NetAPI.execute(ProGuard:212) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.HTTPPostClient.execute(ProGuard:96) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.concrete\_sendpacket(ProGuard:385) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.sendPostPacket(ProGuard:354) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.send(ProGuard:282) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.threads.RequestQueueConsumer.run(ProGuard:30) W/System.err( 5551): at java.lang.Thread.run(Thread.java:841) W/System.err( 5551): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI\_NODATA (No address associated with hostname) W/System.err( 5551): at libcore.io.Posix.getaddrinfo(Native Method) W/System.err( 5551): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61) W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:405) W/System.err( 5551): ... 16 more W/System.err( 5551): Caused by: libcore.io.ErrnoException: getaddrinfo failed: EINVAL (Invalid argument) W/System.err( 5551): ... 19 more W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:424) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.NetAPI.execute(ProGuard:212) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.HTTPPostClient.execute(ProGuard:96) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.concrete\_sendpacket(ProGuard:385) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.sendPostPacket(ProGuard:354) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.send(ProGuard:282) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.threads.RequestQueueConsumer.run(ProGuard:30) W/System.err( 5551): at java.lang.Thread.run(Thread.java:841) W/System.err( 5551): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI\_NODATA (No address associated with hostname) W/System.err( 5551): at libcore.io.Posix.getaddrinfo(Native Method) W/System.err( 5551): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61) W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:405) W/System.err( 5551): ... 16 more W/System.err( 5551): Caused by: libcore.io.ErrnoException: getaddrinfo failed: EINVAL (Invalid argument) W/System.err( 5551): ... 19 more E/[SAEngine]( 5551): retry W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:394) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.NetAPI.execute(ProGuard:212) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.HTTPPostClient.execute(ProGuard:96) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.concrete\_sendpacket(ProGuard:385) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.sendPostPacket(ProGuard:354) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.send(ProGuard:282) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.threads.RequestQueueConsumer.run(ProGuard:39) W/System.err( 5551): at java.lang.Thread.run(Thread.java:841) W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:394) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) W/System.err( 5551): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.NetAPI.execute(ProGuard:212) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.HTTPPostClient.execute(ProGuard:96) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.concrete\_sendpacket(ProGuard:385) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.sendPostPacket(ProGuard:354) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.RequestPOST.send(ProGuard:282) W/System.err( 5551): at com.sec.android.app.samsungapps.vlibrary.net.threads.RequestQueueConsumer.run(ProGuard:39) W/System.err( 5551): at java.lang.Thread.run(Thread.java:841) E/[SAEngine]( 5551): retry W/System.err( 5551): java.net.UnknownHostException: Unable to resolve host "us-odc.samsungapps.com": No address associated with hostname W/System.err( 5551): at java.net.InetAddress.lookupHostByName(InetAddress.java:394) W/System.err( 5551): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) W/System.err( 5551): at java.net.InetAddress.getAllByName(InetAddress.java:214) W/System.err( 5551): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err( 5551): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err( 5551): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)

Ok, I made that error go away by adding back:

“android.permission.ACCESS_NETWORK_STATE”,

I had taken it out because I felt like I was just piling on permissions that didn’t have anything to do with what I was trying to do… this one, in fact was needed.

I hope this helps someone some day, that is why I’m logging my progress. I would love to have someone go, “Oh, I know what he’s doing wrong!” and then post it here but I realize that may not happen.

Are any headers added to the request by network.request()? It seems like you would just automatically add some of them like “Content-Length” being added to a PUT request.

Ok, I fixed this issue. The bottom line is that Android doesn’t like PUT requests. I don’t know why. If you are trying to send a file on an Android device use POST. iOS doesn’t seem to care either way so the platform neutral thing to do is POST.

It was really tough to figure out because nowhere in the error log did it say, “I don’t know what PUT means” or anything like that. I’m just posting this resolution because the solution isn’t really anywhere I could find, I just had to brute force a solution. Hope this helps someone.

Hi, Mark. Couldn’t you share here your code for upload and downloading?

I’m getting some trouble using Michael’s https://code.coronalabs.com/code/dropbox-rest-api-module-corona-sdk. I’m getting some error, and I don’t know where…

Hi Wiler, The only thing I really did different was use a post command instead of a put command:

[lua]

D.putFile = function(path, listener, data, params)

 local url = “https://api-content.dropbox.com/1/files_put/auto/” … path

 params = params or {}

 if not params.headers then

  params.headers = {}

 end

 local headers = params.headers

 headers.Authorization = "OAuth " … string.gsub(authString, “&”, “,”)

 if not headers[“Content-Length”] then

  local fileSize = string.len(data)

  headers[“Content-Length”] = fileSize

 end

 if not params.body then

  params.body = data

 end

 network.request(url, “POST”, getFileListener(listener), params)

end

[/lua]

This is pretty much a cut and paste from my code. I’m using it in several places so I gave myself the option of having a custom body and custom header but the basics default into the POST. How you need to customize it will depend on your app. There are a all kinds of things that might be causing your problem, and they may or may not have anything to do with a POST command. Best thing I can recommend is try to make a separate test app that just uploads a string to DB, get that working and then add the code into your application.

If you want to see the code at work, I have a version of it in this app which was made using Corona SDK: http://www.legendofus.net/wheres-my-sidekick/ I use it both to enable the user to back up files and to enable them to share files. I could never get an email to attach a file on Android so I just upload it to DB and then share a link to the file by email.

One more note, you can still use ‘&’ for options in the POST command… so like after ‘path’ above you could have:

[lua]

… “?option=mychoice&otheroption=mychoice”

[/lua]

@Mark_Steelman, I’ve been using this thread as reference when I have been uploading files to Dropbox, and all is working well when I use the system.ResourceDirectory. However, I’m having through getting the POST call to respect the change to system.DocumentsDirectory. Have you need able to tackle that? If you could share a solution (if you have one) I’d be greatly appreciative. Thanks!

I’ve seen this in a couple of cases using HTML and basically I had to reinforce the change in directory using system.pathForFile.

local myPath = “myfolder/myfile.txt”

local fullPath = system.pathForFile(myPath, system.DocumentsDirectory)

do something like that and then attempt to post the file.

@Mark_Steelman, I’ve been using this thread as reference when I have been uploading files to Dropbox, and all is working well when I use the system.ResourceDirectory. However, I’m having through getting the POST call to respect the change to system.DocumentsDirectory. Have you need able to tackle that? If you could share a solution (if you have one) I’d be greatly appreciative. Thanks!

I’ve seen this in a couple of cases using HTML and basically I had to reinforce the change in directory using system.pathForFile.

local myPath = “myfolder/myfile.txt”

local fullPath = system.pathForFile(myPath, system.DocumentsDirectory)

do something like that and then attempt to post the file.