IIS webdav 和 Ensembles

IIS webdav and Ensembles

我正在尝试通过带 Ensembles 的 IIS 8 Webdav 后端使用同步。我遇到的问题是第一次同步工作正常,但是当我尝试第二次或在第二个单元上同步时(iPad 在这种情况下)我收到服务器错误 405 "method not allowed"。有没有人遇到过这个并让它工作,与 IIS Webdav 同步?

这是服务器响应的 allheaderfield 属性:

" UserInfo={NSLocalizedDescription=HTTP status code was {
    Allow = "COPY, PROPFIND, DELETE, MOVE, PROPPATCH, LOCK, UNLOCK";
    Connection = "Keep-Alive";
    "Content-Length" = 1293;
    "Content-Type" = "text/html";
    Date = "Mon, 25 Jan 2016 12:02:07 GMT";
    "Persistent-Auth" = true;
    Server = "Microsoft-IIS/8.5";
    "X-UA-Compatible" = "IE=8";

编辑: 可能这毕竟不是配置问题。我添加了一些日志,createDirectoryAtPath 方法给我 HTTP 错误 405,这是原始代码:

- (void)createDirectoryAtPath:(NSString *)path completion:(CDECompletionBlock)completion{
NSMutableURLRequest *request = [self mutableURLRequestForPath:path];
request.HTTPMethod = @"MKCOL";
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];

[self sendURLRequest:request completion:^(NSError *error, NSInteger statusCode, NSData *responseData) {
    if (completion) completion(error);
}];}

这是 directoryExistsAtPath 方法:

- (void)directoryExistsAtPath:(NSString *)path completion:(CDEDirectoryExistenceCallback)completion{
[self sendPropertyFindRequestForPath:path depth:0 completion:^(NSError *error, NSInteger statusCode, NSData *responseData) {
    if (error && statusCode != 404) {
        if (completion) completion(NO, error);
    }
    else if (statusCode == 404) {
        if (completion) completion(NO, nil);
    }
    else {
        CDEWebDavResponseParser *parser = [[CDEWebDavResponseParser alloc] initWithData:responseData];
        BOOL succeeded = [parser parse:&error];
        if (!succeeded) {
            if (completion) completion(NO, error);
            return;
        }

        BOOL isDir = [parser.cloudItems.lastObject isKindOfClass:[CDECloudDirectory class]];
        if (completion) completion(isDir, nil);
    }
}];}

如果我将最后的完成块中的第一个参数(当前是 isDir 变量)替换为 YES,405 错误不会 appear.On 记录 parser.clouditems.lastobject,我发现它通常(或总是?)是空的)。因此,将参数设置为 YES,导致数据上传到我的 webdav,并且文件夹就位。但是,在第二个单元上进行测试(或在同一单元上重新安装应用程序)时,下载永远不会发生——永远不会调用 downloadFromPath,永远不会发送 "GET" 请求。

查看底层框架(主要是 CDECloudmanager)中的调用代码到目前为止,我还没有任何进展。

由于 directoryExistsAtPath 是可选的,我尝试将其注释掉,但我认为这没有什么不同。

我注意到的另一件事是我在基线文件夹中得到了几个基线文件。根据 Ensembles 文档,应该只有一个。

有线索吗?

好吧,看来我终于成功了。我必须在 CDEWebDavCloudFileSystem class 中进行更改以避免 405 错误。但是,这样做时,我遇到了 404 错误。那个是通过配置 IIS webdav 解决的。

所以第 1 步,我更改了 sendPropertyFindRequestForPath 方法中的请求:

新代码:

static NSString *xml = @"<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\"><D:allprop/></D:propfind>";

原码:

static NSString *xml = @"<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\"><D:prop><D:href/><D:resourcetype/><D:creationdate/><D:getlastmodified/><D:getcontentlength/><D:response/></D:prop></D:propfind>";

要删除之后出现的 404 错误,我必须将 mime 类型 application/xml 添加到 .cdeevent 扩展名。

此 link 详细介绍了如何为此配置 IIS:

http://anandthearchitect.com/2013/08/01/webdav-404file-or-directory-not-found/