iPhone - 解析后是否可以在服务器上删除 xml 文件
我目前正在通过托管 Apache http 服务器来解析托管在另一台 PC 上的 xml 文件,该服务器工作正常。现在是否有可能以这样的方式编码,让 iPhone 删除该电脑上的 xml 文件?
我当前使用 NSMutableURLRequest 并将其设置为 NSData。
NSError * error;
NSURLResponse * response;
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://ipaddress/UserBedData.xml"]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:5.0];
[request setHTTPMethod:@"GET"];
NSData * responseData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
xmlParser = [[NSXMLParser alloc] initWithData:responseData];
im currently parsing an xml file that is hosted on another PC via hosting a Apache http server which works fine. Now is it possible to code it in such a way that the iPhone deletes the xml file on that pc?
im currently using a NSMutableURLRequest and setting it to an NSData.
NSError * error;
NSURLResponse * response;
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://ipaddress/UserBedData.xml"]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:5.0];
[request setHTTPMethod:@"GET"];
NSData * responseData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
xmlParser = [[NSXMLParser alloc] initWithData:responseData];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对另一台服务器有多少控制权?我假设您拥有完全访问权限。
考虑定期清理 XML。在您知道不再需要文件后,每小时运行一次 cron 作业并删除文件。也许可以在后端创建一个列表,记录数据何时被访问,以便数据可以安全地过期。
如果没有关于您正在做什么的更多详细信息,就很难缩小方法的范围。为什么你不能在 iPhone 上解析 XML? XML feed 是否可以动态生成,这样就没有文件需要清理? XML 数据从哪里来?在这种情况下,发布代码不一定会有帮助。您应该详细说明所有部分如何组合在一起(iPhone 应用程序、远程服务器、数据)以及您想要完成的任务。
它甚至是 XML 文件的集合吗?或者它总是同一个?如果只是一个文件,为什么需要删除它?只需在重新生成旧版本时覆盖旧版本(并在某处添加日期戳,以便下载它的客户端知道它何时真正过时)。
How much control do you have over this other server? I assume you have full access.
Consider simply cleaning the XML up periodically. Run a cron job and delete files every hour after you know they aren't needed any more. Maybe create a list on the backend that logs when data has been accessed, so that it can be safely expired.
Without further details on what you're doing, the approach is difficult to narrow down. Why can't you parse the XML on the iPhone e.g.? Can the XML feeds be generated dynamically, so there's no file to clean up? Where is the XML data coming from? This isn't necessarily a situation where posting your code is going to help. You should elaborate on how all the piece fit together (the iPhone app, the remote server, the data) and what you're trying to accomplish.
Is it even a collection of XML files? Or is it always the same one? If it's just one file, why do you need to delete it? Simply overwrite the old one when it gets regenerated (and datestamp it somewhere, so the client who downloads it knows when it's really out of date).
仅当服务器允许时。如果 Web 服务器正确设置了 WebDAV,则动词 DELETE 和文件的 URL 应该可以执行此操作(假设您提供适当的凭据,因为让任何人删除内容是一个坏主意)。
删除与获取几乎相同。只需将
"GET"
替换为"DELETE"
并忽略返回的内容。然而,存在身份验证问题,这在阅读网站时通常并不重要,但当您想要删除网站上的某些内容时,身份验证问题就非常重要。恐怕我在这方面帮不了你。还要考虑@joost的答案,这可能比允许客户端删除服务器上的内容更安全。Only if the server lets it. If the web server has WebDAV setup properly, the verb DELETE, with the URL of the file should do it (assuming you supply appropriate credentials, since it's a bad idea to let just anyone delete content).
The deletion is almost identical to the fetch. Simply replace
"GET"
with"DELETE"
and ignore the returned content. There is, however, the question of authentication, which usually doesn't matter when reading a web site, but matters a whole lot when you want to delete some content on the web site. I can't help you on that front, I'm afraid. Also consider @joost's answer, which is probably safer than allowing clients to delete stuff on the server.