Hello all I have written a pretty basic program which automatically dials stargates(a plugin thta provide instantanious treansport between any two locations with a gate) on my server, Currently the program asks the user where they want to go, and then searches my database for an address via a php page.
However it appears that when lua submits the request to my page, it cuts the data off after the first space, causing it to get the wrong address
As you see when you go here: http://projectbuilde...e=nulls%20house
It properly returns the address to my house.
My code is included below, you can run it on any computer in game to see that when you type "nulls house" it will try to dial "nulls TARDIS", because it doesn't include the second word when submitting the request. (http://projectbuilde...gate&name=nulls)
Below is my code:
http://pastebin.com/2YND8rRp (to make it work you need 3 monitors above the pc, and the pc must have a label set)
I think for some reason the input is not being read properly, it seems to stop after the first space.
Lua Cutting A String Short? (How To Change Space To %20)
Started by NullSchritt, Aug 09 2013 03:17 PM
5 replies to this topic
#1
Posted 09 August 2013 - 03:17 PM
#2
Posted 09 August 2013 - 03:29 PM
However it seems that I can dial the address if I type in "nulls%20house" and it will work fine.
How should I go about replacing spaces in input string with %20?
How should I go about replacing spaces in input string with %20?
#3
Posted 09 August 2013 - 03:33 PM
You need to encode the url before using it. Look at the url you provided:
http://projectbuilde...e=nulls%20house
note the %20 between nulls and house, that's an encoded space. CC provides a function to do this: textutils.urlEncode(string). Use it on the variables you want to add to the url, like this:
http://projectbuilde...e=nulls%20house
note the %20 between nulls and house, that's an encoded space. CC provides a function to do this: textutils.urlEncode(string). Use it on the variables you want to add to the url, like this:
content = http.get("http://smp.projectbuilder.info/fetch.php?cmd=page&ID=dialgate&buffer=0&name=" .. textutils.urlEncode(destination))
#4
Posted 09 August 2013 - 03:51 PM
MysticT, on 09 August 2013 - 03:33 PM, said:
You need to encode the url before using it. Look at the url you provided:
http://projectbuilde...e=nulls%20house
note the %20 between nulls and house, that's an encoded space. CC provides a function to do this: textutils.urlEncode(string). Use it on the variables you want to add to the url, like this:
http://projectbuilde...e=nulls%20house
note the %20 between nulls and house, that's an encoded space. CC provides a function to do this: textutils.urlEncode(string). Use it on the variables you want to add to the url, like this:
content = http.get("http://smp.projectbuilder.info/fetch.php?cmd=page&ID=dialgate&buffer=0&name=" .. textutils.urlEncode(destination))
#5
Posted 09 August 2013 - 03:59 PM
Well, I need to see the code to check for other errors, can you upload it again (it looks like you deleted it or it expired)?
#6
Posted 09 August 2013 - 04:05 PM
Nevermind! I was updating the wrong version of my code, it works now, thanks!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











