WebDav创建目录时添加try防止报错

pull/981/head
gedoor 4 years ago
parent 7c7ea811d4
commit e894038271
  1. 4
      app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt
  2. 9
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt

@ -119,4 +119,8 @@ fun Request.Builder.postJson(json: String?) {
val requestBody = json.toRequestBody("application/json; charset=UTF-8".toMediaType())
post(requestBody)
}
}
fun Request.Builder.mkCol() {
method("MKCOL", null)
}

@ -1,5 +1,6 @@
package io.legado.app.lib.webdav
import io.legado.app.help.http.mkCol
import io.legado.app.help.http.newCall
import io.legado.app.help.http.okHttpClient
import io.legado.app.help.http.text
@ -148,9 +149,9 @@ class WebDav(urlStr: String) {
return kotlin.runCatching {
okHttpClient.newCall {
url(url)
method("MKCOL", null)
mkCol()
addHeader("Authorization", Credentials.basic(auth.user, auth.pass))
}
}.close()
}.isSuccess
}
return false
@ -192,7 +193,7 @@ class WebDav(urlStr: String) {
url(url)
put(fileBody)
addHeader("Authorization", Credentials.basic(auth.user, auth.pass))
}
}.close()
return true
}
return false
@ -208,7 +209,7 @@ class WebDav(urlStr: String) {
url(url)
put(fileBody)
addHeader("Authorization", Credentials.basic(auth.user, auth.pass))
}
}.close()
return true
}
return false

Loading…
Cancel
Save