Created
May 12, 2023 21:28
-
-
Save stokito/0f05d2c9b92ce9c51b5092e8057cb6d0 to your computer and use it in GitHub Desktop.
Sample of WebDAV PROPFIND from JavaScript with fetch api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>WebDAV Ajax sample</title> | |
<script> | |
let davUrl = "http://192.168.1.1/dav" | |
function list() { | |
fetch(`${davUrl}/`, { | |
method: 'PROPFIND', | |
credentials: 'include', | |
headers: { | |
'Content-Type': 'application/json', | |
'Depth': '1' | |
}, | |
referrerPolicy: 'no-referrer', | |
body: '' | |
}) | |
.then(handleFetchError) | |
.then((resp) => { | |
console.log(resp.headers) | |
console.log(resp.statusText) | |
return resp.ok | |
}) | |
.catch((error) => { | |
console.log('Failed: ', error) | |
}) | |
} | |
function handleFetchError(response) { | |
if (!response.ok) { | |
throw Error(response.statusText); | |
} | |
return response; | |
} | |
</script> | |
</head> | |
<body> | |
<button onclick="list()">Fetch</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment