BUG - Network.request not accepting queries in the URL when running on Android.

Hello,

We are having troubles with “Network.request()” function. I’ve tried in different versions of coronasdk including the latest daily build.

The following code doesn’t work fine on Android (and it works perfecly on iOS):

local base\_url = "mysite.com" local url = base\_url .. "/wp-json/posts?filter[posts\_per\_page]=20" .. "&filter[category\_name]=category" local params = {}    params.progress = true    params.timeout = 40 network.download( url, "GET", options.listenerFunction, params, targetFilePath, options.target\_baseDirectory )

I’m sending a request to an API. 

When running on iOS (or in the simulator) I’m getting the correct results because the App is making the request to the correct url:

"mysite.com/wp-json/posts?filter[posts_per_page]=20&filter[category_name]=category"

But when running on Android devices, I’m getting the results equivalent to:

"mysite.com/wp-json/posts?filter[posts_per_page]=20"

Which means that network.request on Android is not understanding the complete URL with two queries. 

If I change the url to 

**"mysite.com/wp-json/posts?filter[category_name]=category&****filter[posts_per_page]=20 **"

On android I get the results equivalent to:

"mysite.com/wp-json/posts?filter[category_name]=category"

So its clear that there is a bug on Android ignoring what comes after the “&”.

have tried [==[I am a string &]==] instead of “I am a string &”
Basically use [==[]==] instead of quotes

Have you tried fully qualifying the URL:

https://mysite.com/wp-json/posts?filter[posts_per_page]=20&filter[category_name]=category

Yes, I’ve tried with the complete URL (including http://). I’m sure this is a bug, the same code works fine on iOS and is buggy on Android. 

I’m wondering if Android is sensitive to the []'s in your GET key-value pairs. Normally non-letter/numbers have to be URL encoded. You can use a function like:

local function urlencode(str) if (str) then str = string.gsub (str, "\n", "\r\n") str = string.gsub (str, "([^%w])", function (c) return string.format ("%%%02X", string.byte(c)) end) str = string.gsub (str, " ", "+") end return str end

and assemble your URL like:

local url = base\_url .. "/wp-json/posts?" .. urlencode("filter[posts\_per\_page]") .. "=20" .. "&  .. urlencode("filter[category\_name]") .. "=category"

If the values 20 and category can every contain non-letter/numbers you would need to encode them as well.

See if that helps.

Just tried the “urlencode” fix. Doesn’t work either.

Hey Rob, could you please check this our? I’m pretty sure I’m facing a Corona BUG. Please let me know how I can help you.

If you feel this is a bug, I encourage you to file a bug report. The bug report should contain a simple demonstration app that lets us build for device and run it and see the problem. Therefore it needs a main.lua, config.lua, build.settings, the actual URL’s you’re trying to access that causes the problem. Put the whole demo project in a .zip file and use the Report a Bug link at the top of the page.

You will get an email confirming the bug report. It will have a case ID number in the subject, please post that case ID number back here as a reference. I’ll grab the bug report and see if I can see the problem when I see your live production code. If it’s a bug, then it will be in the system. If not we will know the cause and you can proceed.

Rob

o

Has this issue been resolved? I’m facing probably a similar situation with our self hosted parse server. If there is a workaround would love to hear about it.

I can’t find a bug report for it.

Rob

Perhaps they worked around it somehow? Would love to know how…

Want params are you use in your parse request? Basically what your request look like. Are you use the parse plugin via corona marketplace, making your own, or using mod_parse

Actually I tried both and got the same behavior on Android device. It’s a simple get request for parse users sorted by their XP value and limited to top 25. I don’t have it near me so can’t send the actual URL.

Ok I assumed this bug and you problem might be related because it way not working android and I just remembered this bug. But post the url when you get a chance.

I think you nailed it. Good catch as I did not see this thread. I will try to file a bug report end of next week when I’m back from our family vacation. I don’t understand how such a bug evaded the core team for so long. It seems a very basic behavior that many encounter. Unless there is some obvious workaround I’m not familiar with.

I’ve tried the new update of parse plug-in and still get the issue. I wondered since the plug-in uses native libs if it could have avoided the issue, but probably they use the default network lib by Corona, so the issue remains.

I will open a bug for that

Can you post a sample request you are using? I have a custom parse database I can try it on.

Hi,

I’m not sure how the request is sent since there is no way to know what network.request compiles. However, the input to this method for example is: (users table assumes to have the following additional columns: xp,rank,play,win)

url:

<your self hosted parse base url>/users

body:

{“order”:"-xp",“limit”:7,“keys”:“username,xp,rank,play,win”}

headers:

Accept: application/json

Content-Length: 60

Content-Type: application/json

X-Parse-Application-Id: <your app id>

X-Parse-REST-API-Key: <your rest API key>

X-Parse-Session-Token: <your session token>

When sent via simulator, this returns exactly 7 entries, sorted by most XP. When sent via android device, this returns all entries in the table, unsorted.

Hello Everyone, 

Has this bug been fixed yet? A major feature in my application depends highly on this to work. I have successfully integrated Google Drive into my application, but multiple queries must be in the URL in order for it to work. My application is currently only available on Android, and I am looking to release this update in the next week for my customers. Please fix this ASAP!

Thanks,

Feliz Games

I have a drive plugin on the way and it works fine. The big problem I believe was the way the url was written. If you have having trouble with this and you believe this is a bug then report it. The worst corona can say is it not a bug and explain why it is not a bug. https://developer.coronalabs.com/content/bug-submission