Skip to content

Instantly share code, notes, and snippets.

@stokito
Created May 12, 2023 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stokito/0f05d2c9b92ce9c51b5092e8057cb6d0 to your computer and use it in GitHub Desktop.
Save stokito/0f05d2c9b92ce9c51b5092e8057cb6d0 to your computer and use it in GitHub Desktop.
Sample of WebDAV PROPFIND from JavaScript with fetch api
<!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