1
votes

I need to make HTTP DELETE request to my server with body provided.

I build the retrofit object in the following way:

        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(interceptor)
                .retryOnConnectionFailure(true)
                .connectTimeout(2, TimeUnit.MINUTES)
                .readTimeout(5, TimeUnit.MINUTES)
                .writeTimeout(5, TimeUnit.MINUTES)
                .build();

        Gson gson = new GsonBuilder()
                .registerTypeAdapter(Date.class, new GsonUTCDateAdapter())
                .registerTypeAdapter(LocalDate.class, new GsonLocalDateAdapter())
                .create();

        return new Retrofit.Builder()
                .baseUrl(AppConfig.API_BASE_URL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();

My Retrofit service method is:

@HTTP(method = "DELETE", path = "selfie/{publicId}/action/1", hasBody = true)
Observable<SimpleResponseModel> unlike(
    @Path("publicId") String publicId,
    @Body AuthorisedRequestModel model
);

I handle retrofit request/response in following way:

                NetworkHelper
                .getRetrofit()
                .create(SelfieService.class)
                .unlike(selfieModel.getPublicId(), new AuthorisedRequestModel())
                .subscribeOn(Schedulers.io())

                .subscribe(new CustomSubscriber<SimpleResponseModel>() {
                    @Override
                    public void onNext(SimpleResponseModel simpleResponseModel) {
                        ErrorHelper.handleServerError(simpleResponseModel);
                    }
                });

I should mention, that all another requests GET,POST and PUT are working, but all DELETE requests are return me following error, from log:

HTTP FAILED: java.io.IOException: unexpected end of stream on okhttp3.Address@c6ec992c

So the request don't reach the server.

When I used Retrofit without rxandroid and made queries in AsyncTasks everything worked well.

Caused by:

Caused by: java.io.EOFException: \n not found: size=0 content=…
 at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:215)
 at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
1

1 Answers

0
votes

It is an issue. You can see it on GitHub: https://github.com/square/okhttp/issues/1517