由swisspol提供的开源库GCDWebServer是一个轻量的HTTPserver,它基于GCD并可用于OSX&iOS,该库还实现了基于web的文件上传以及WebDAVserver等扩展功能。
使用方法:
#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;}
评论