【问题标题】:How to get local html file through gcdwebserver如何通过gcdwebserver获取本地html文件
【发布时间】:2016-09-13 08:39:39
【问题描述】:

我在 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
  • 我在 iphone app 文档目录中有 html 文件,当我点击 localhost url 时我想要 html 数据

标签: ios gcdwebserver


【解决方案1】:

你可能没有正确设置websitePath,试试:

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

【讨论】:

    猜你喜欢
    • 2016-03-08
    • 2019-11-26
    • 2018-02-21
    • 2016-05-18
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    • 2018-12-19
    相关资源
    最近更新 更多