我需要有一個Web服務,使我的iPhone應用程序可以連接到數據庫,讓我做這些功能:iphone Web服務
- 登錄/註銷會員
- 註冊爲會員
- 從數據庫
- 獲取的個人資料從數據庫
檢索圖像,我如何做到這一點,一些導遊或AP非常不確定擔任上述職能的援助公司將非常受歡迎。
我需要有一個Web服務,使我的iPhone應用程序可以連接到數據庫,讓我做這些功能:iphone Web服務
檢索圖像,我如何做到這一點,一些導遊或AP非常不確定擔任上述職能的援助公司將非常受歡迎。
您必須在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;
}
}
?>
「您必須在php中編寫如下代碼,並使用NSURL與服務器連接。」 - 你根本不需要這麼做,它只是衆多選擇/解決方案之一。 – AnthonyBlake 2012-02-06 14:07:41
我沒有處理在我的應用程序註冊新用戶,登錄/註銷,獲取一些數據的一個web服務.. web服務寫在.Net和我通過肥皂信息處理它..如果你有興趣,我會爲你解釋它..祝你好運。
它不是一個關於iphone的問題 – rakeshNS 2012-02-06 09:25:59
我同意Rakesh。嘗試使用php或.net webservices。 – Sarah 2012-02-06 09:33:43
@rakeshNS也完全同意,將標籤更改爲:php,web-services,.net,web開發,但我的編輯被奇怪地拒絕了。 – AnthonyBlake 2012-02-06 14:06:59