Network.Request - To Read URL Parameters and Values

I want to read the values in txtFirstName a variable being passed in the following example url address:

http://www.library.com/elib1/elib/booknum/onenter.asp? txtFirstName=OFF SEASON ~ SIDDONS, ANNE RIVERS~ 2008~ GRAND CENTRAL PUB.~ WIDOWS FICTION

Basically I have a website that I want to pass database values back to an iPhone App. TxtFirstName holds the values being passed. I have this worked out in a Visual Basic program in Windows that when the above URL is called the values in TxtFirstname are striped away into variables, with the ~ being the delimiter to distinguish the values in the TxtFirstname variable.

I am trying the following code below but all I get is the contents of the page in html.


local url = "http://www.library.com/elib1/elib/booknum/onenter.asp?txtFirstName=OFF SEASON ~ SIDDONS, ANNE RIVERS~ 2008~ GRAND CENTRAL PUB.~ WIDOWS FICTION


local function networkListener( event )"

if ( event.isError ) then
print( “Network error!”)
else
print ( "RESPONSE: " … event.response )
end
end

network.request( url, “GET”,networkListener,txtFirstName )

How does the 3rd parameter in network. request work? [import]uid: 22152 topic_id: 15956 reply_id: 315956[/import]

Where do you want to read the values off the URL? From Lua or from your website?

If you want to read them off Lua, then why are you invoking the URL? All you need is a string parser that will read the stuff off your URL string.

If you want to read it on the webserver, then this is the wrong forum for that.

For details on network.listener, you might want to read up on http://developer.anscamobile.com/reference/index/networkrequest and this will pass data to the URL not read from it.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15956 reply_id: 59104[/import]

I want to read them off Lua but how do I parse the variable txtFirstName which contains the data in the URL? The ~ is separating the values. [import]uid: 22152 topic_id: 15956 reply_id: 59116[/import]

you mentioned VB, so can you use string parsing? using the sub command or finding the position of the ? and the position of the = and picking up the variable name between these and the data after the =

to get you started,

 local url = "....."  
  
 local pos1, pos2 = 0,0  
  
 pos1 = string.find(url,"?")  
 pos2 = string.find(url,"=")  
  
 if pos1==0 or pos2==0 then return end --Not found  
  
 local varName = url:sub(pos1+1, pos2-1)  
 local data = url:sub(pos2+1)  
  
 print(varName)  
  

Now try to use something like the split (VB6) command or go through each character of the string and when you find the ~ character, put the string till the position into a table, then you have a table full of data

hope that helps you forwards,

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15956 reply_id: 59127[/import]