如何使用 iPhone 应用程序从服务器访问数据
我正在为 iphone 构建一个联系人备份应用程序。我已使用 POST 方法将地址簿联系人作为 plist 文件上传到 http 服务器。现在我想从服务器检索这些联系人并将它们加载到地址簿中。现在我想知道如何从服务器获取这些数据?也许我可以使用 GET 请求。但我不知道如何执行它。
我在上传数据的服务器上使用了以下 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";
}
?>
现在我必须在应用程序中编写一个可以从服务器检索信息的方法。我还需要哪些 php 代码来支持从服务器检索数据?
如果您对这些主题有所了解,请与我分享一些信息。
谢谢。
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. 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.
I have used the following php code for server where i am uploading data.
<?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?
Please share some information with me if you know anything about these topics.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许简单的
echo
会有帮助?您可以轻松地在 Xcode 应用程序中重新创建数据。
Maybe simple
echo
will help?You can easily recreate data in Xcode app.
我不确定 PHP,但您需要创建一种方法来接受来自 iPhone 应用程序的请求并以 xml 或 JSON 格式返回数据。或者您也可以发送文件。如果您以 XML 或 JSON 格式发送数据,那么您需要对其进行解析。
此外,您还可以使用 POST 方法在 iPhone 应用程序中获取数据。 POST 和 GET 方法仅用于参数。这并不意味着您要使用 GET 方法获取数据。
另外,如果您可以尝试一些事情然后回来,那么我们可以为您提供适当的指导。在这个阶段,很难让你走上正确的道路。
首先,你先做 PHP 部分,然后考虑 iPhone 代码。
希望此概述有所帮助。
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. Or you can send file too. if you send data in XML or JSON format then you need to do parsing for that.
Also, You can also get data in iPhone app using POST method. POST and GET method is just for parameter. It doesn't mean that you are going to Get data in GET Method.
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.
Hope this overview help.
如果构建 iPhone 应用程序,我建议使用 http://allseeing-i.com/ASIHTTPRequest/How -使用如何格式化数据取决于您。您可以发送整个 plist 文件或在传输之前将其转换为其他格式
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. you could send the whole plist file or make it into another format before transmission