简体   繁体   English

如何使用iPhone应用程序从服务器访问数据

[英]How to access data from a server using an iphone application

I am building a contact backup application for iphone.I have uploaded address-book contacts to a http server using POST method as a plist file.Now i want to retrieve these contacts from server and load them to the address book. 我正在为iphone构建联系人备份应用程序。我已经使用POST方法将通讯录联系人上传到http服务器作为plist文件。现在我想从服务器中检索这些联系人并将其加载到通讯录中。 Now i want to know how can i get these data from server?May be i could use GET request.But i don't know how to perform it. 现在我想知道如何从服务器获取这些数据?也许我可以使用GET request。但是我不知道如何执行它。

I have used the following php code for server where i am uploading data. 我已将以下php代码用于我要上传数据的服务器。

<?php
$target = "./upload/";
print_r($_FILES);
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(is_uploaded_file($_FILES['uploaded']['tmp_name']))
{
   move_uploaded_file($_FILES['uploaded']['tmp_name'], $target);
   echo "YES";
}
else
{
   echo "Not uploaded";
}
?> 

Now i have to write a method in application which can retrieve information from server.And also what php code i need to support retrieving data from server? 现在我必须在应用程序中编写一个可以从服务器检索信息的方法。还要支持从服务器检索数据的php代码?

Please share some information with me if you know anything about these topics. 如果您对这些主题有任何了解,请与我分享一些信息。

Thanks. 谢谢。

I am not sure about PHP but you need to make one Method which accepts request from the iPhone app and return data in either xml or JSON format. 我不确定PHP,但您需要制定一种方法来接受iPhone应用程序的请求,并以xml或JSON格式返回数据。 Or you can send file too. 或者,您也可以发送文件。 if you send data in XML or JSON format then you need to do parsing for that. 如果您以XML或JSON格式发送数据,则需要对此进行解析。

Also, You can also get data in iPhone app using POST method. 另外,您还可以使用POST方法在iPhone应用程序中获取数据。 POST and GET method is just for parameter. POST和GET方法仅用于参数。 It doesn't mean that you are going to Get data in GET Method. 这并不意味着您将要使用GET方法获取数据。

Also, if you can try something and then come back then we can guide you appropriately. 另外,如果您可以尝试一些然后再回来的话,我们可以适当地指导您。 At this stage it is very difficult to take you on correct track. 在此阶段,很难带您正确走上正轨。

First of all, do you PHP part and then think about iPhone code. 首先,让您开始使用PHP,然后考虑一下iPhone代码。

Hope this overview help. 希望本概述对您有所帮助。

Maybe simple echo will help? 也许简单的echo会有所帮助?

<?php

header('Content-Type: text/xml');

echo file_get_contents('./upload/YOURFILENAME.plist');

?>

You can easily recreate data in Xcode app. 您可以轻松地在Xcode应用中重新创建数据。

If building an iphone app I recommend using http://allseeing-i.com/ASIHTTPRequest/How-to-use how you format the data is up to you. 如果要构建iPhone应用程序,我建议您使用http://allseeing-i.com/ASIHTTPRequest/如何格式化数据的方法。 you could send the whole plist file or make it into another format before transmission 您可以发送整个plist文件或将其制成其他格式,然后再进行传输

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从iPhone应用程序向服务器发送数据 - how to send data to server from iphone application 如何使用URL将数据从iPhone发送到服务器 - How to send data from iphone to server using the url 如何使用Windows应用程序从Web服务器访问数据 - how can access data from a webserver using a windows application 如何在Php Server上识别,应用程序是从使用推送通知服务的iPhone中删除的 - How to identify at Php Server , application is delete from the iphone which is using push notification servies 使用php使用NSURLConnection将数据从服务器发送到iPhone - Sending data from server to iPhone with NSURLConnection using php 如何将数据从iPhone发送到服务器并在站点中显示 - How to send data from iPhone to a Server and show it in the site 如何从Ubuntu的Laravel应用程序访问Windows服务器中的文件? - How to access files within a Windows server from a Laravel application in Ubuntu? 将数据从服务器发送到iPhone应用程序 - Send data from server to iPhone app 通过iPhone中的php从服务器访问数据 - Accessing data from server through php in iphone 如何通过同一网络上的iPhone访问Mac localhost PHP服务器上的网站? - How can I access website on Mac localhost PHP server from an iPhone on the same network?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM