Just a point to note.
For iOS, you need the " http://" in front or it won’t work.
For Android, it is free & easy…
Just a point to note.
For iOS, you need the " http://" in front or it won’t work.
For Android, it is free & easy…
Was there ever a solution to this? I’m running in to the same problem. Grabbing URLs from a list and most are fine, but when they happen to be malformed, there’s no error to the listener, they just fail.
URL’s need to be URL encoded. Perhaps you’re running into that issue. See:
http://coronalabs.com/blog/2014/11/11/tutorial-encoding-urls-for-network-usage/
Rob
Well yes, but reasonably should the event.isError say that?
The problem I have, as with the original poster, is using a database of previously URL encoded urls – where, obviously, a couple URLs aren’t correctly encoded. You can’t easily re-encode a full URL. So because no error is returned, you’re basically saying we would need to pick apart the query string of URL, de-encode it, re-encode and put it back together.
Which, from the perspective of Corona being there to make things easier – well, isn’t very easy. It prints to the console “Invalid Parameter: URL argument was malformed URL” – but there’s nothing we can do with that from the console. If only it would return that same message in “event.isError”, we could handle it and move on (in my case, that would mean ignoring that URL and moving to the next in the list).
Make sense?
We are frequently at the mercy of what the Operating System gives us. Perhaps the OS doesn’t trigger it’s call back because it never tries the URL. In that case perhaps we should return something from network.request() like:
local success, message = network.request(…)
if not success then
print( message )
end
But I don’t even know if that’s possible. I seriouslly suspect that the error is happening before the request is made and that’s why it’s failing to trigger the call back.
Corona does try to make things easier and given infinite resources we probably could tackle every thing, but as of now, it’s your responsibility to urlencode each query parameter. When you get the data from the database, if your app expects to use it, it’s got to parse it into Lua variables in the first place.
Rob
Yeah, I’d be fine with ANYTHING more than a message to the console that can seemingly only be used by me visually seeing it in the corona simulator console.
Of course I did try getting a message result directly from the call itself – but indeed, that doesn’t return anything in either success or fail. Same goes for the loadRemoteImage call. It returns nil in every case.
When you get the data from the database, if your app expects to use it, it’s got to parse it into Lua variables in the first place.
Which is just/should be just populating a table.
Anyway – given this… Any thoughts on how one could check their own URLs? The more I think about it, the more trouble I have.
If I have 2 URLs, one that is already URL encoded and one that is not … How do I check to see which is which – encoding an already encoded URL isn’t feasible. I’m trying to think through dissecting a URL and checking the parts but perhaps that exists somewhere?
For example:
http://www.Google.com/?q=something with a / is confusing?
http://www.Google.com/?q=something%20with%20a%20%2F%20is%20confusing%3F
You could use a string.match() to look for the presence of a percent sign followed by a number.
if string.match(URL, “%%%d”) then
– has been URL encoded
else
– has not been
end.
I’ve not tested it, but something like that should work. The only gotcha is if there are only spaces and they were URL encoded to +'s, then you might want to do a second check. If your URL encode routine is turning spaces into %20’s then you would be okay with that test.
http://www.Google.com/?q=something
would fail that test… and then I have to disassemble and reassemble the variations of URLs… those with ? query strings and those with them buried in a standard looking url.
It also leaves the issue of encoding a url.
For example, you can’t just urlencode http://www.Google.com/?q=something … cause that gives you
http%3A%2F%2Fwww.Google.com%2F%3Fq%3Dsomething
You’re going to have to split off the query string regardless. You can’t pump the whole URL through URL encode. I know we posted a string recipe tutorial a year or so a go. There are a ton of string.split() functions that can be found on google, or you can always do it with string match too.
Rob
… Right, which reinforces the frustration of seeing the URL error in the console and having no way to get that inside the app code itself.
I’m bringing in the URLs via json from a remote server running PHP … Given that, I found this function seems to work to sanitize the URLs before sending them to the corona app… Just posting it should anyone else get here from a search.
function LOCAL\_FIX\_URL ($url) { $encoded\_url = preg\_replace\_callback('#://([^/]+)/([^?]+)#', function ($match) { return '://' . $match[1] . '/' . join('/', array\_map('rawurlencode', explode('/', $match[2]))); }, $url); return $encoded\_url; }
Just a point to note.
For iOS, you need the " http://" in front or it won’t work.
For Android, it is free & easy…