轻量的HTTP服务器:GCDWebServer
jopen
10年前
由swisspol提供的开源库GCDWebServer是一个轻量的HTTP server,它基于 GCD 并可用于 OS X & iOS,该库还实现了基于web的文件上传以及 WebDAV server等扩展功能。
使用方法:
#import "GCDWebServer.h" #import "GCDWebServerDataResponse.h" static GCDWebServer* _webServer = nil; // This should really be an ivar of your application's delegate class - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { // Create server _webServer = [[GCDWebServer alloc] init]; // Add a handler to respond to GET requests on any URL [_webServer addDefaultHandlerForMethod:@"GET" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) { return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello World</p></body></html>"]; }]; // Start server on port 8080 [_webServer startWithPort:8080 bonjourName:nil]; return YES; }