Android networ.request() response empty

I’m developing an advertising system for Corona https://github.com/pubnative/pubnative-corona-library/tree/development which first verion is located here.

I’m having problems with the network request that is working just fine for ios devices and simulator, while Android is giving me  a 400 status response with empty response

My corona build is

Version 2014.2511 (2014.11.18)

And this is the network.request event data

Thanks in advance

 

Are you by any chance going through a redirect?

Nope, that is an API Request that always  comes with an json response, without redirects.

Is there anything on the server that would give you a clue why the server is giving you a 400 error?

Rob

Hi Rob:

No, if you get that URL in the browser of any other device you successfully get a response, but for some reason, CoronaSDK built for Android gets an error 400.

Cheers

The server should have some reason it’s giving a 400 error.

Actually it could be this (if you copy/pasted the info)

&device_model=Nexus 5&bundle_id

See how the first part of what you typed is treated as a URL then the space between Nexus and 5 turns the second part into regular text?  That’s because spaces are not allowed in URLs.  The browser fixes this for you and perhaps iOS and the simulator is doing the same thing.  Spaces have to be represented as either a plus sign ( + ) or a %20.  This is called URL encoding.  The values passed to the keys in the GET string key-value pairs.   There are other things that needed encoded too.  Pretty much any thing other than a letter or number in a value needs converted to a %XX value.  Google :   “Lua URL encode” for some methods to do this for you.

Here is the function I use:

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

Hey Rob:

That did the work perfectly

Thanks a lot for your help

Are you by any chance going through a redirect?

Nope, that is an API Request that always  comes with an json response, without redirects.

Is there anything on the server that would give you a clue why the server is giving you a 400 error?

Rob

Hi Rob:

No, if you get that URL in the browser of any other device you successfully get a response, but for some reason, CoronaSDK built for Android gets an error 400.

Cheers

The server should have some reason it’s giving a 400 error.

Actually it could be this (if you copy/pasted the info)

&device_model=Nexus 5&bundle_id

See how the first part of what you typed is treated as a URL then the space between Nexus and 5 turns the second part into regular text?  That’s because spaces are not allowed in URLs.  The browser fixes this for you and perhaps iOS and the simulator is doing the same thing.  Spaces have to be represented as either a plus sign ( + ) or a %20.  This is called URL encoding.  The values passed to the keys in the GET string key-value pairs.   There are other things that needed encoded too.  Pretty much any thing other than a letter or number in a value needs converted to a %XX value.  Google :   “Lua URL encode” for some methods to do this for you.

Here is the function I use:

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

Hey Rob:

That did the work perfectly

Thanks a lot for your help