ios - 如何通过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];

https://stackoverflow.com/questions/37272857/

相关文章:

c# - MongoDB 和 C#,如何按星期比较

c# - Asp.Net Web Api 在 Godaddy 服务器上不工作,但在本地工作正常

python - NoReverseMatch 在/accounts/signup/django-a

amazon-web-services - AWS API Gateway 默认响应和触发器 AWS

clojure - 为什么我们在 Clojure 中需要所有 3 个 - tesser、transd

android - CardView 内的 ExpandableListView 不会改变其父级高度

angularjs - angularjs处理异常的方法

spring - Spring 中的 RequestMapping 包

python - Django模型实例的full_clean方法,是这样吗?

ios - UIPageViewController 不允许识别 UIScreenEdgePanGe