查询参数无效:% 编码无效

invalid query parameters: invalid %-encoding

我尝试通过 Retrofit / Multipart 上传图片 (jpg)。 Api 总是 returns 代码 400 和 "invalid query parameters: invalid %-encoding" 不知道怎么回事

我的界面:

@Headers("Content-type: application/x-www-form-urlencoded", "Accept: application/vnd.mypb+json; version=7")
@POST("/alerts/actions/unknown_pid")
@Multipart
fun uploadPhoto(@Part body: MultipartBody.Part): Call<String?>

我的webservice上传照片方法:

fun uploadPhoto(bitmap: Bitmap) {
    val imageFile = File(context.cacheDir, "image.jpg")

    val baos = ByteArrayOutputStream()
    bitmap.compress(Bitmap.CompressFormat.JPEG, 15, baos)
    val byteArray = baos.toByteArray()

    val fos = FileOutputStream(imageFile)
    fos.write(byteArray)
    fos.flush()
    fos.close()

    val filePart = RequestBody.create(MediaType.parse("image/*"), imageFile)
    val body = MultipartBody.Part.createFormData("document[file]", "photo.jpg", filePart)

    service.uploadPhoto(body).enqueue(object : LoggingCallback<String?>() {
        override fun onSuccess(responseBody: String?) {
            EventBus.getDefault().post(OnPhotoUploadSuccessfulEvent())
        }

        override fun onFailure(response: Response<String?>) {
            EventBus.getDefault().post(OnPhotoUploadFailedEvent())
        }
    })
}

查尔斯回应:

你的header不正确。

您可以删除 headers Content-type: application/x-www-form-urlencoded

或者您应该更改为 Content-type: multipart/form-data