Webdav with curl vs Javascript

拜拜、爱过 提交于 2020-04-30 08:48:43

问题


I try to access a Nextcloud server using Webdav. Using curl this works:

curl -X PROPFIND -u user:pwd https://nextcloudserver.com/remote.php/dav/files/user

Using Javascript this I get a 503 error

const url = "https://nextcloudserver.com/remote.php/dav/files/user/"
var xhr = new XMLHttpRequest();
xhr.open('PROPFIND', url, true);
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:pwd"));
xhr.withCredentials=true;
xhr.send();

Any idea?


回答1:


this is working for me:

const url = "https://nextcloudserver.com/public.php/webdav/";
var objHTTP = new XMLHttpRequest();
objHTTP.open('PROPFIND', url, true);
objHTTP.setRequestHeader("OCS-APIRequest","true");
objHTTP.setRequestHeader("Authorization", "Basic " + Base64.encode("username:password"));
objHTTP.onreadystatechange = function() {
    if (objHTTP.readyState == XMLHttpRequest.DONE) {
        console.log(objHTTP.responseText);
    }
}
objHTTP.send();

Regards, Roberto



来源:https://stackoverflow.com/questions/60155260/webdav-with-curl-vs-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!