如何请求和接收自定义生成的XML文件? [英] How to request and receive a custom generated XML File?

查看:67
本文介绍了如何请求和接收自定义生成的XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为iPhone创建一个应用程序,该应用程序应该能够连接到服务器并下载xml文件.每次请求该文件时,都应该从数据库中重新生成该文件.

I would like to create an app for iPhone which should be able to connect to a server and download an xml file. The file should be freshly generated from a database every time it is requested.

例如,假设有一个向用户推荐书籍的应用程序,其中服务器根据每个请求生成推荐书.
首先,没有信息将从应用程序传输到服务器.该应用程序始终请求相同的文件,该文件将使用或多或少的随机内容生成.在接下来的步骤中,我希望传输登录信息以能够分别回答请求,但这不是最重要的事情.

As an example, imagine an app that recommends books to the user, where the recommendations are generated by the server upon each request.
At first, no information will be transmitted from the app to the server. The app requests always the same file which will be generated with more or less random content. In a later step, I'd like to transmit login information to be able to answer the requests individually, but this is not the top priority.

为了简单起见,我想依靠通用"基础结构,例如运行php的简单网络服务器.该应用程序定位于利基市场,我不希望重载.

To keep things simple, I'd like to rely on "common" infrastructure, like a simple webserver running php. The app targets a niche and I'm not expecting heavy loads.

您将如何实现这样的功能?您将如何处理在应用程序中创建请求/连接到服务器以及xml文件的传递?可以在服务器端使用php完成此操作,还是需要更专业的操作?

How would you implement such a feature? How would you handle creating the request within the app / connecting to the server and the delivery of the xml file? Can this be done using php on the serverside or would this require something more specialized?

非常感谢!

推荐答案

好的,我自己找到了一个简单的解决方案(在php-pro的帮助下).

OK I found a simple solution myself (with a little help from a php-pro).

首先,我会让我的应用程序请求一个php文件(带有希望作为参数接收的项目数),如下所示:

First I'd let my app request a php file (with the number of items I wish to receive as argument) like this:

NSString *sourcePath = [NSString stringWithFormat:@"http://www.foobar.com/db_getxml.php?%i", numberOfItems];

NSURLRequest *newRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:sourcePath]];

NSURLResponse *response;
NSData *loadResult = [NSURLConnection sendSynchronousRequest:newRequest returningResponse:&response error:NULL];

该php文件将从mysql数据库读取请求的条目数,然后输出xml数据.

The php file will read the requested number of entries from a mysql database and then output xml data.

我需要做的只是将 loadResult 的内容填充到xml解析器中-可以正常工作.

All I need to do is stuff the contents of loadResult into the xml parser - works perfectly.

这篇关于如何请求和接收自定义生成的XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆