WebDAV return 401 - How to authenticate?

2019-06-13 01:29发布

I have a problem with WebDAV. I have to get a list of files. I have this request:

<?xml version="1.0"?>
<D:searchrequest xmlns:D = "DAV:">
<D:sql>
    SELECT "DAV:displayname" FROM "address" WHERE "DAV:ishidden" = false AND "DAV:isfolder" = false 
</D:sql>
</D:searchrequest>

Response:

401 - Unauthorized: Access is denied due to invalid credentials.

I have user and password (who has access), but I don't know, how I can put this data to XML request.

1条回答
beautiful°
2楼-- · 2019-06-13 01:54

WebDAV uses an HTTP authentication.

So you put your credentials to an HTTP header, not to the WebDAV XML in the HTTP body.

The basic HTTP authentication works like:

  • You get a WWW-Authenticate header from the server

    WWW-Authenticate: Basic realm="server"
    
  • You include the Authorization header to the next request. The value of the header is:

    Authorization: Basic username:password
    

    where the username:password is in Base-64 encoding.

    Authorization: Basic dXNlcjpwYXNzd29yZA==
    

For details, see

查看更多
登录 后发表回答