Remote http call

Hey guys…

I need to do something and can’t figure out how to resolv my issue!

I have this test code :

[code]local http = require(“socket.http”)

– 5 Second timeout
http.TIMEOUT = 5

– The return parameters are in a different order from luup.inet.wget(…)
result, status = http.request(“http://192.168.168.169/message.php?message=THIS IS A TEST”, “”)[/code]

The problem is, I only receive THIS on the other side… looks like the http.request stop after any space.

If I use my browser with the URL

http://192.168.168.169/message.php?message=THIS IS A TEST

It’s works fine, so I know my problem came from LUA!

I know it works if I use %20 instead of space… but I want to avoid using %20 in LUA, Or any LUA function to find/replace so I can replace space with %20 ?

Any idea…

thanks

I put this function in my Startup Lua so i can use it to encode text for URLs. (original is from https://gist.github.com/ignisdesign/4323051)

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, " ", "%%20") end return str end

if you call

urlencode("THIS IS A TEST")

It will return:
THIS%20IS%20A%20TEST

Thanks mda

Works fine :slight_smile: