2012-02-06 99 views
1

我需要有一个Web服务,使我的iPhone应用程序可以连接到数据库,让我做这些功能:iphone Web服务

  1. 登录/注销会员
  2. 注册为会员
  3. 从数据库
  4. 获取的个人资料从数据库

检索图像,我如何做到这一点,一些导游或AP非常不确定担任上述职能的援助公司将非常受欢迎。

+3

它不是一个关于iphone的问题 – rakeshNS 2012-02-06 09:25:59

+0

我同意Rakesh。尝试使用php或.net webservices。 – Sarah 2012-02-06 09:33:43

+0

@rakeshNS也完全同意,将标签更改为:php,web-services,.net,web开发,但我的编辑被奇怪地拒绝了。 – AnthonyBlake 2012-02-06 14:06:59

回答

0

您必须在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; 
} 
} 
?> 
+0

“您必须在php中编写如下代码,并使用NSURL与服务器连接。” - 你根本不需要这么做,它只是众多选择/解决方案之一。 – AnthonyBlake 2012-02-06 14:07:41

0

我没有处理在我的应用程序注册新用户,登录/注销,获取一些数据的一个web服务.. web服务写在.Net和我通过肥皂信息处理它..如果你有兴趣,我会为你解释它..祝你好运。