如何通过gcdwebserver获取本地html文件



我在iphone模拟器中运行本地GCDWebServer,我在文档目录中存储了一些html文件,现在我想通过GCDWebServer访问该html文件,我正在尝试但没有得到响应,请帮助我

代码:

[self addGETHandlerForBasePath:@"/" directoryPath:folderpath indexFilename:nil cacheAge:3600 allowRangeRequests:YES];
[self addHandlerForMethod:@"GET"
                pathRegex:@"/.*.html"
             requestClass:[GCDWebServerRequest class]
             processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
    NSDictionary* variables = [NSDictionary dictionaryWithObjectsAndKeys:@"value", @"variable", nil];
    return [GCDWebServerDataResponse responseWithHTMLTemplate:[websitePath stringByAppendingPathComponent:request.path]
                                                    variables:variables];
}];

[self addHandlerForMethod:@"GET"
                     path:@"/"
             requestClass:[GCDWebServerRequest class]
             processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
    return [GCDWebServerResponse responseWithRedirect:[NSURL URLWithString:@"index.html" relativeToURL:request.URL]
                                            permanent:NO];
];

您可能没有正确设置websitePath,请尝试:

websitePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];

相关内容

  • 没有找到相关文章

最新更新