Retrofit Android + Spring Boot Server images uploading return Bad Request 错误
Retrofit Android + Spring Boot Server images uploading return Bad Request error
我在这里读了很多关于它的问题,但它对我不起作用。可能是我做错了什么?
我的改装界面:
@Multipart
@POST("/api/v1/services/add")
suspend fun addServiceAsync(@Part("newService") service: ServiceApiData,
@Part imageFile:MultipartBody.Part?,
@Header("Authorization") jwt:String?): StatusAndStrApi?
而Spring RestController部分是
@PostMapping("/add")
ResponseEntity<?> addService(@RequestPart(name = "newService") ServiceServer service,
@RequestPart("imageFileFromClient") MultipartFile imageFile
)
这里是我如何创建 Multipatr.Body:
MultipartBody.Part.createFormData(
"imageFileFromClient",
fileImage.name,
fileImage.asRequestBody("image/*".toMediaTypeOrNull()
)
这里是什么服务器 return 我:
I/okhttp.OkHttpClient: <-- 400 http://server:8080/api/v1/services/add (301ms)
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
I/okhttp.OkHttpClient: Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: application/json
I/okhttp.OkHttpClient: Transfer-Encoding: chunked
Date: Fri, 03 Sep 2021 05:11:18 GMT
Connection: close
{"timestamp":"2021-09-03T05:11:18.689+00:00","status":400,"error":"Bad Request","path":"/api/v1/services/add"}
I/okhttp.OkHttpClient: <-- END HTTP (110-byte body)
I/System.out: close [socket][/100.107.22.171:34172]
尝试使用 https 而不是 http。
BODY WAS NULL,但它不应该是。不允许 Multipartbody 可以为空。从来没有。
我在这里读了很多关于它的问题,但它对我不起作用。可能是我做错了什么?
我的改装界面:
@Multipart
@POST("/api/v1/services/add")
suspend fun addServiceAsync(@Part("newService") service: ServiceApiData,
@Part imageFile:MultipartBody.Part?,
@Header("Authorization") jwt:String?): StatusAndStrApi?
而Spring RestController部分是
@PostMapping("/add")
ResponseEntity<?> addService(@RequestPart(name = "newService") ServiceServer service,
@RequestPart("imageFileFromClient") MultipartFile imageFile
)
这里是我如何创建 Multipatr.Body:
MultipartBody.Part.createFormData(
"imageFileFromClient",
fileImage.name,
fileImage.asRequestBody("image/*".toMediaTypeOrNull()
)
这里是什么服务器 return 我:
I/okhttp.OkHttpClient: <-- 400 http://server:8080/api/v1/services/add (301ms)
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
I/okhttp.OkHttpClient: Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: application/json
I/okhttp.OkHttpClient: Transfer-Encoding: chunked
Date: Fri, 03 Sep 2021 05:11:18 GMT
Connection: close
{"timestamp":"2021-09-03T05:11:18.689+00:00","status":400,"error":"Bad Request","path":"/api/v1/services/add"}
I/okhttp.OkHttpClient: <-- END HTTP (110-byte body)
I/System.out: close [socket][/100.107.22.171:34172]
尝试使用 https 而不是 http。
BODY WAS NULL,但它不应该是。不允许 Multipartbody 可以为空。从来没有。