I called PATCH web service using Retrofit2 but onResponse is not called and the onFailure is called Despite of
Thank you very much.
Api
@FormUrlEncoded
@POST("/rebu/insertusuario.php")
Call<Void> insertLogin(
@Field("email") String email,
@Field("senha") String senha,
@Field("codCondutor") Long codCondutor
);
Class:
Call call = service.insertLogin(login.getEmail(), login.getSenha(), login.getCodCondutor());
just return void instead, if the body is empty
@PATCH("alerts/{alert_id}/accept") Call<Void> accept_invited_alerts(@Header("X-Api-Token") String api_token, @Path("alert_id") int alert_id);
for retrofit with Rx java you can use something like this
@PATCH("alerts/{alert_id}/accept") Observable<Response<Void>> accept_invited_alerts(@Header("X-Api-Token") String api_token, @Path("alert_id") int alert_id);
You can create NullOnEmptyConverterFactory.class :
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
public class NullOnEmptyConverterFactory extends Converter.Factory {
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
final Converter<ResponseBody, ?> delegate = retrofit.nextResponseBodyConverter(this, type, annotations);
return new Converter<ResponseBody, Object>() {
@Override
public Object convert(ResponseBody body) throws IOException {
if (body.contentLength() == 0) return null;
return delegate.convert(body);
}
};
}
}
and add to code create. For ex:
UploadImageNghiemThuApi uploadService = new Retrofit.Builder()
.baseUrl(Config.URL+"/")
.client(okHttpClient)
// -----add here-------
.addConverterFactory(new NullOnEmptyConverterFactory())
//---------------------
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(UploadImageNghiemThuApi.class);
I hope it can help your problem. Thanks!