PDA

View Full Version : HTTP Submit - How do I get return values


SeizeTheDave
12-06-2005, 04:08 PM
In TU v1.0, I was able to submit to a web page and have values sent back to me in the web page. For example, I would receive an html page that looked like this:

<TRUEUPDATE10>%value1%,%value2%</TRUEUPDATE10>

<%value1%>Hello</%value1%>

<%value2%>World</%value2%>


From there I could use "%value1%" and "%value2%" as actual variables within my script.

How do I do this now? The HTTP.Submit seems to only put all of this into a string. Is there a way to get the values without having to write a function to parse through the results?

I have tried sending back a string that looks like {value1="Hello",value2="World"} in hopes of turning it into an array. That didn't work.

Any ideas? Thanks!

Dave

Brett
12-07-2005, 09:11 AM
You are right in that it does not automatically parse out variables anymore. The best thing to do in my opinion is to have your server script return XML text and then use the XML actions to parse it up.

If you do return a script such as:

tblData = {value1="Hello",value2="World"};

Take the string and save it to a file using TextFile.WriteFromString to write it to a file and then use Application.LoadScript to load the script file in. Then the tblData values will be available to your scripts from there.

Mark
12-07-2005, 09:52 AM
Hi SeizeTheDave,

You can also take advantage of the built-in lua function loadstring() which basically loads a string into the lua engine and assigns it to an anonymous function.

Here's an example that I got working:

I created a php script that returned the following information:
value1="Hello";value2="Hello2";

Then I ran the HTTP.Submit action and stored the return value in the variable "result"

After that I ran the following code to load the variables into the engine:

f = loadstring(result);
f();


Now the variables value1 and value2 have been loaded into the lua engine with the values "Hello" and "Hello2" respectively.

Here is all the code listing:


result = HTTP.Submit("HTTP://XXX/mark.php", {},SUBMITWEB_POST, 30, 80, nil, nil);
f = loadstring(result);
f();
Dialog.Message(value1,value2);

SeizeTheDave
12-21-2005, 06:54 AM
Hey guys! Thanks for the replies. I ended up going with the XML. It works great!