diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt index b6d50f116..e47a4abfa 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt @@ -53,6 +53,8 @@ fun buildRequest(request: Request, callback: UrlRequest.Callback): UrlRequest { val contentType: MediaType? = requestBody.contentType() if (contentType != null) { requestBuilder.addHeader("Content-Type", contentType.toString()) + } else { + requestBuilder.addHeader("Content-Type", "text/plain") } val buffer = Buffer() requestBody.writeTo(buffer) diff --git a/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt b/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt index 6147ff1db..cbdbd15ce 100644 --- a/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt +++ b/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt @@ -131,7 +131,7 @@ object BookWebDav { WebDav(exportsWebDavUrl).makeAsDir() // 如果导出的本地文件存在,开始上传 val putUrl = exportsWebDavUrl + fileName - WebDav(putUrl).upload(byteArray) + WebDav(putUrl).upload(byteArray, "text/plain") } } catch (e: Exception) { Handler(Looper.getMainLooper()).post { @@ -153,7 +153,7 @@ object BookWebDav { val json = GSON.toJson(bookProgress) val url = getProgressUrl(book) if (initWebDav()) { - WebDav(url).upload(json.toByteArray()) + WebDav(url).upload(json.toByteArray(), "application/json") } } } diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index e09b83c46..93e3752b2 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -185,11 +185,14 @@ class WebDav(urlStr: String) { /** * 上传文件 */ - suspend fun upload(localPath: String, contentType: String? = null): Boolean { + suspend fun upload( + localPath: String, + contentType: String = "application/octet-stream" + ): Boolean { val file = File(localPath) if (!file.exists()) return false // 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 - val fileBody = file.asRequestBody(contentType?.toMediaType()) + val fileBody = file.asRequestBody(contentType.toMediaType()) val url = httpUrl val auth = HttpAuth.auth if (url != null && auth != null) { @@ -204,9 +207,9 @@ class WebDav(urlStr: String) { return false } - suspend fun upload(byteArray: ByteArray, contentType: String? = null): Boolean { + suspend fun upload(byteArray: ByteArray, contentType: String): Boolean { // 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 - val fileBody = byteArray.toRequestBody(contentType?.toMediaType()) + val fileBody = byteArray.toRequestBody(contentType.toMediaType()) val url = httpUrl val auth = HttpAuth.auth if (url != null && auth != null) {