如何使一个Ajax/Cors请求webDav存储

How to make an Ajax/Cors request to a webDav storage?

本文关键字:请求 webDav 存储 Cors 何使一 Ajax      更新时间:2023-09-26

我正在尝试编写一个javascript/jquery插件,仅访问JSON-data的webDav存储,我正在努力让它工作。

webDav将是一个远程存储,所以我需要做一个跨域的ajax请求,沿着身份验证数据传递。

我尝试了各种版本,但我总是在preflight认证上失败,而我可以正确访问文件,当我直接在浏览器中输入URL(并提供登录凭据)。

这是我尝试过的:

$.ajax({
  url: priv.url + '/' + priv.user + '/' +
    priv.foldertree + '/' + docid,
  type: "GET",
  async: true,
  crossdomain : true,
  headers : {
    Authorization: 'Basic ' + Base64.encode(
      priv.user + ':' + priv.password
      )
  },
  success: function (content) {
    console.log( content );
  }
});

我还设置了以下内容,没有运气:

 xhrFields: {withCredentials: 'true'}
 contentType: 'text/plain'

或:

 datatype: "jsonp"

或:

 username: priv.user
 password: priv.password

或:

 beforeSend: function (xhr) {
  xhr.setRequestHeader ('Authorization', 
      "Basic" + Base64.encode( priv.user + ':' + priv.password )
    );
  }

但所有我得到的是一个401 authorization failed响应从远程服务器对我的preflight options请求。

问题:
我无法访问远程服务器,但由于它是远程WebDav存储即服务,因此应该可以访问我计划存储在那里的文件。有人能给我一个指针如何正确地使请求得到我的JSON数据(我还需要张贴,profind,删除,但首先的事情…)?

谢谢!

明白了。提供程序设置不允许使用webDAV/Ajax/preflight/身份验证。

切换提供商(Otixo) -现在可以工作了。