I need to communicate with our web site and wanted to get some advice.
I need to have my user activate their app to unlock more functionality. I want to send from the iOS app The users last name and Membership number.
Then the Web site needs to look up that number and respond Yes or No.
I was thinking of having a php file (I think Xojo would be overkill) on the web that will do the lookup. In the future I would like to create a Web API but thats a little further down the road.
If you are considering php, take a look at http://www.codeigniter.com/. Very easy to use and very solid. We’ve written a complete REST api that runs using CodeIgniter for our company, communicating with thousands of mobile devices (Androids in our case) every day. Pity Xojo seems to have gven up on WebSockets because e.g. with B4X and WebSockets, setting up a a webserver and communicating (even push) with Android, iOS devices and web browsers can be done in a matter of minutes. (That is how the next version of our API will be written).
I don’t need that. Our site is a drupal site and have no need to introduce another framework.
I actually have a php file that does the look up, but that was called from Adobe Flex app from iOS and Android. But I’m moving the app to Xojo and need to learn the best way to do this.
If you already have a PHP file that does the lookup and returns a result, then you can just call it using an HTTPSocket and check the result in the PageReceived event handler.
I’m trying to test it with @Paul Lefebvre Test Rest app. Can get it to pass 1 variable but not 2. I was doing this so I can then dissect what I need for my app.
I’m having a little trouble wrapping my thick scull around this.
$UserName = $_POST ['txtLastName'];
$MemNum = $_POST ['txtMebershipNumber']; //5772;
$LoginRS__query = sprintf ( "Select Lastname, MemStatus from tblpeople where MemberNumber = %s AND LastName = '%n' and
(tblpeople.MemStatus = 'Sent To VPM 1' or tblpeople.MemStatus = 'Sent To VPM 2'
or tblpeople.MemStatus = 'Back From VPM' or tblpeople.MemStatus = 'Active Member' or tblpeople.MemStatus = 'Renewal')", $MemNum, $UserName);
I am printing out the varable $LoginRS__query which shows up in the response.
This is what came back sending:
txtMebershipNumber=42044&txtLastName=Albrecht
Response:
Select Lastname, MemStatus from tblpeople where MemberNumber = 42044 AND LastName = '' and
(tblpeople.MemStatus = 'Sent To VPM 1' or tblpeople.MemStatus = 'Sent To VPM 2'
or tblpeople.MemStatus = 'Back From VPM' or tblpeople.MemStatus = 'Active Member' or tblpeople.MemStatus = 'Renewal')
I’m not a PHP guy, but what is %n in the sprintf method? Should it be %s? And since you add the quotes in sprintf you don’t need to pass them in the POST.
After watching the Webinar on web rest services, I could do it like that. It looks like a no Brainer. My only question is, isn’t that a little overboard for sending 2 pieces of data and getting back a yes or no?
Another question, won’t it be slow as when it’s called it has to load? PHP is practically instantaneous.
After its called from the remote client (iOS) how long does it stay in memory and is there a way to get it to terminate?
WHich end do you need help with?
The xojo end or the web end?
At the Xojo end:
[code]//socket is global / window property
Dim d As New Dictionary
d.Value(“txtLastName”) = “Smith”
d.Value(“txtMembershipNumber”) = “ABCD1234”
Socket.SetFormData(d)
Dim result As String
result = Socket.Post(“http://www,somesite.com/response.asp”, 30) // Synchronous
result = DefineEncoding(result, Encodings.UTF8)[/code]
This should work as the content of a simple ASP page at the other end that always returns ‘Yes’
[code]
<%
dim Surname
Surname=Request.Form(“txtLastName”)
dim Membership
Membership=Request.Form(“txtMembershipNumber”)
'check it here
dim valid
valid = true
if valid then
response.write(“Yes”)
else
response.write(“No”)
end if
%>
$LoginRS__query = sprintf ( "Select Lastname, MemStatus from tblpeople where MemberNumber = %s AND LastName = '%s' and
(tblpeople.MemStatus = 'Sent To VPM 1' or tblpeople.MemStatus = 'Sent To VPM 2'
or tblpeople.MemStatus = 'Back From VPM' or tblpeople.MemStatus = 'Active Member' or tblpeople.MemStatus = 'Renewal')", $MemNum, $UserName);
echo $LoginRS__query;
?>[/code]
And called it with RESTy using this as the Request Content:
txtMembershipNumber=42044&txtLastName=Albrecht
I get back this:
Select Lastname, MemStatus from tblpeople where MemberNumber = 42044 AND LastName = 'Albrecht' and
(tblpeople.MemStatus = 'Sent To VPM 1' or tblpeople.MemStatus = 'Sent To VPM 2'
or tblpeople.MemStatus = 'Back From VPM' or tblpeople.MemStatus = 'Active Member' or tblpeople.MemStatus = 'Renewal')