network.request Invalid Parameter: URL argument was malformed URL

hi,

i’m using a network.download request on my mac that involves adding a hebrew word to it

and when i print to screen the request and then copy paste to my safari everything works perfactly

but then on the simulator

i get error >

“network.request Invalid Parameter: URL argument was malformed URL”

and everything i do is good,

addedText = “אבי ביטון”

local paramFormat = “&chefn=”… addedText

local request = “http://80.74.111.131/marsutf8/recipes.aspxCmd=Get&InfoID=11&parm1=1&parm2=300”… paramFormat

network.download(request, “GET”, networkListener3, “search.xml”, system.DocumentsDirectory  )

can you please fix this annoying bug that prevents me from building my app ?

Hi @Mars Interactive,

This may not be the exact issue here, but did you try setting your content-type header encoding to UTF-8? Networking is not my specialty (I can refer you to Rob or somebody else for more detailed assistance), but try experimenting with the properties in the “params” table as shown here:

http://docs.coronalabs.com/api/library/network/download.html

[lua]

content-type: application/x-www-form-urlencoded; charset=UTF-8

[/lua]

Thanks,

Brent

if you could ask someone to fix it that would be great

the thing is i looked and looked and looked but all of the people are saying to me: “Lua doesn’t know anything about UTF-8”

offcures i tried experimenting with the encoding… nothing is working on it though …

The problem is that you need to urlencode the Hebrew characters to make them legal in a URL (your browser is doing this behind the scenes).
 
Something like this would work:

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 function networkListener3(event) print\_r( event ) end addedText = "אבי ביטון" local paramFormat = "&chefn=".. urlencode(addedText) local request = "http://127.0.0.1/marsutf8/recipes.aspxCmd=Get&InfoID=11&parm1=1&parm2=300".. paramFormat network.download(request, "GET", networkListener3, "search.xml", system.DocumentsDirectory)

great !!! your awsome it works !!! :slight_smile:

Hi @Mars Interactive,

This may not be the exact issue here, but did you try setting your content-type header encoding to UTF-8? Networking is not my specialty (I can refer you to Rob or somebody else for more detailed assistance), but try experimenting with the properties in the “params” table as shown here:

http://docs.coronalabs.com/api/library/network/download.html

[lua]

content-type: application/x-www-form-urlencoded; charset=UTF-8

[/lua]

Thanks,

Brent

if you could ask someone to fix it that would be great

the thing is i looked and looked and looked but all of the people are saying to me: “Lua doesn’t know anything about UTF-8”

offcures i tried experimenting with the encoding… nothing is working on it though …

The problem is that you need to urlencode the Hebrew characters to make them legal in a URL (your browser is doing this behind the scenes).
 
Something like this would work:

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 function networkListener3(event) print\_r( event ) end addedText = "אבי ביטון" local paramFormat = "&chefn=".. urlencode(addedText) local request = "http://127.0.0.1/marsutf8/recipes.aspxCmd=Get&InfoID=11&parm1=1&parm2=300".. paramFormat network.download(request, "GET", networkListener3, "search.xml", system.DocumentsDirectory)

great !!! your awsome it works !!! :slight_smile:

@Perry - CoronaLabs Team

I was searching all day to figure out how I could do that (same issue as Mars but with Arabic characters). You know that you have developers from all around the globe so PLEASE consider pointing that out in the documentations, it will definitely help others!

Hi @MustafaAlyousef,

Thank you for the reminder. I will add this example to the “network.download()” documentation soon.

Brent

@Perry - CoronaLabs Team

I was searching all day to figure out how I could do that (same issue as Mars but with Arabic characters). You know that you have developers from all around the globe so PLEASE consider pointing that out in the documentations, it will definitely help others!

Hi @MustafaAlyousef,

Thank you for the reminder. I will add this example to the “network.download()” documentation soon.

Brent