我有图像文件要上传到服务器。API是
Content-Type:application/x-www-form-urlencoded
.
下面是我的接口方法
@Headers("Content-Type: application/octet-stream")
@PUT
Call<UserIdentity> putUserProfileImage(@Url String url,
@Body RequestBody file);
这是我的方法调用
RequestBody requestBody = RequestBody
.create(MediaType.parse("application/octet-stream"), profileImage);
appCMSUserIdentityRest.putUserProfileImage(url, requestBody).enqueue(new Callback<UserIdentity>() {
@Override
public void onResponse(@NonNull Call<UserIdentity> call,
@NonNull Response<UserIdentity> response) {
if (response.body() != null) {
Observable.just(response.body())
.onErrorResumeNext(throwable -> Observable.empty())
.subscribe(userIdentityAction);
}else{
Observable.just((UserIdentity) null)
.onErrorResumeNext(throwable -> Observable.empty())
.subscribe(userIdentityAction);
}
}
@Override
public void onFailure(@NonNull Call<UserIdentity> call, @NonNull Throwable t) {
Observable.just((UserIdentity) null)
.onErrorResumeNext(throwable -> Observable.empty())
.subscribe(userIdentityAction);
}
});
}
我总是收到错误的请求。