[英]iphone web services
我需要一个Web服务,以便我的iPhone应用程序可以链接到数据库,以允许我执行以下功能:
我不确定如何执行此操作,将非常欢迎一些具有上述功能的指南或付费公司。
您必须在php中编写以下代码,然后使用NSURL与服务器连接。
在Xcode中:
NSError *error = nil;
NSHTTPURLResponse *response;
NSString *post =[NSString stringWithFormat:@"http://Yourserveraddress/demo/adminemailvalidation.php?email=%@&type=%@",Email.text,@"admin"]; //here you have to bind the parameters.
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:post]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSData *serverReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
根据serverReply数据,您必须验证凭据。
服务器端:
<?php
mysql_connect('localhost','pikesol','india12345');
mysql_select_db('pikesol_india');
$FamilyName=$_GET['familyname'];
$Authenticated=$_GET['authenticated'];
if(!empty($FamilyName) &&!empty($Authenticated))
{
$query=mysql_query("select FirstName,LastName,Email from memberrequests where FamilyName ='$FamilyName' and Authenticated ='$Authenticated' ");
$var ;
$num_rows = mysql_num_rows($query);
if ($num_rows >0)
{
$xml_output = "<?xml version=\"1.0\"?>";
$xml_output .= "<entries>";
while($row=mysql_fetch_array($query)){
$xml_output .= "<entry>";
$xml_output .= "<firstname>".$row['FirstName']."</firstname>";
$xml_output .= "<lastname>".$row['LastName']."</lastname>";
$xml_output .= "<email>".$row['Email']."</email>";
$xml_output .= "</entry>";
}
$xml_output .= "</entries>";
echo $xml_output;
}
else
{
$var='No';
echo $var;
}
}
?>
我确实在我的一个应用程序中处理了Web服务,以注册新用户,登录/注销,获取一些数据.. Web服务是用.Net编写的,我通过肥皂消息来处理..如果您感兴趣的话我会为您进一步解释..祝您好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.