OGeek|极客世界-中国程序员成长平台

标题: ios - 如何使 HTTP Web 服务托管在 iOS 上? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:15
标题: ios - 如何使 HTTP Web 服务托管在 iOS 上?

我需要制作一个 HTTP 网络服务或一个 HTTP 操作页面,托管在 iPad 或任何 iOS 设备上。 应该可以从使用 HTTPRequest 或使用 NSURLConnection 连接在同一网络上的其他设备访问此服务。

任何建议都会很有用。



Best Answer-推荐答案


您需要一个用 cocoa 编写的 Web 服务器,该服务器在您的应用程序中运行并通过 HTTP 提供对文件的访问


无耻插件:看我的 DDSimpleHTTPd——它是一个在 iOS 设备上运行的基本网络服务器

https://github.com/Daij-Djan/DDSimpleHTTPd

在您的 viewController/appDelegate 中,您可以像这样启动它以服务器指定目录中的任何文件:

NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString *path = url.path;

SimpleHTTPResponder *simpleServer = [[SimpleHTTPResponder alloc] init];
simpleServer.port = 8000;
simpleServer.webRoot = path;
simpleServer.bonjourName = @"test"; //optional: allow it to be found via bonjour
simpleServer.loggingEnabled = YES; //optional: do NSLogs of the requests that come in
simpleServer.autogenerateIndex = YES; //optional: generate a directory overview

[simpleServer startListening];

关于ios - 如何使 HTTP Web 服务托管在 iOS 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24010680/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4